from sys import setrecursionlimit setrecursionlimit(1000000) fibs = {} frames = 0 # Pre-seed with the first couple # This IS our base case # We don't need a separate base case then fibs[1] = 1 fibs[2] = 1 def fib(x): global frames frames += 1 if x in fibs: return fibs[x] fx = fib(x-1) + fib(x-2) fibs[x] = fx return fx # CYthon crashes if we go more than 20,000 at once # pypy crashes sooner than that # Interpreter weaknesss...we can work around it print(fib(20000)) print(fib(40000)) print(fib(60000)) # warmup for the big one for i in range(60000,1000000,20000): fib(i) print(str(int(i/1000)) + "K") # Now we're ready! print(fib(1000000))