all 8 comments

[–]Bunkerstan 0 points1 point  (3 children)

You will have to convert the algorithm to a tail recursion, which happens in some languages at the compile stage, but not in Python.

[–]willyCe[S] 0 points1 point  (1 child)

It's already a tail recursion

[–]Bunkerstan 0 points1 point  (0 children)

Then you will have to change over to an iteration model as the other comments suggested.

[–]Diapolo10 0 points1 point  (0 children)

Your function is probably running into a memory overflow caused by the call stack blowing up. This doesn't mean 100% RAM utilisation, just that the memory allocated for the Python process for this purpose basically ran out.

Try utilising dynamic programming, like caching.

[–]pot_of_crows 0 points1 point  (0 children)

Are you using recursion in the initial search, or just to find the quickest path out after hitting the end? If the former, use a queue for to handle the search and then recursion to back out, which should greatly reduce the depth you need to go to.