Trying to solve a recursion problem of travelling along the grid. The function works correctly up to approximately a grid of size 500 x 500. If it is further increased an Abort trap: 6 is thrown.
The second try, except was added to try to catch the Abort trap, but it does not catch it. As it is not an Error I assume.
Could the issue be that the number of paths becomes simply too large? As at 500x500 it is 6.763970e+298
def gridTraveler2(m: int, n: int, memo = {}) -> int:
""" Given a grid of m x n, starting in top left and going to bottom right
how many ways are there
m > n plz
"""
try:
return memo[(m, n)]
except:
if m == 1 or n == 1:
memo[(m, n)] = 1
else:
try:
memo[(m, n)] = gridTraveler2(m - 1, n, memo = memo)\
+ gridTraveler2(m, n - 1, memo = memo)
except:
memo[(m, n)] = 0
print("Something went wrong with setting memo")
return memo[(m, n)]