|
|
|
|
|
by spatulon
2814 days ago
|
|
Or turn it into a simple iterative process, instead of a recursive process. They explain how quite simply in SICP: http://sarabander.github.io/sicp/html/1_002e2.xhtml (Ctrl-F "We can also formulate an iterative process for computing the Fibonacci numbers.") Here's a Python implementation: def fib(n):
a = 1
b = 0
i = 0
while i < n:
temp = a
a += b
b = temp
i += 1
return a
With that, fib(100000) takes half a second to compute on my machine. |
|