|
|
|
|
|
by blt
4746 days ago
|
|
The fastest way to calculate the Fibonacci sequence (with integer math) is a simple loop, just like you'd do it on paper. This version is slower and much more complicated. With so many relevant good examples of recursion and dynamic programming, it boggles my mind to see the Fibonacci sequence used as an example for either. def fib(n):
a, b = 0, 1
for k in range(n):
a, b = b, a + b
return a
|
|