I am interested in an iterative algorithm for Fibonacci numbers, so I found the formula on wiki...it looks straight forward so I tried it in Python...it doesn\'t have a prob
How about this simple but fastest way... (I just discovered!)
def fib(n):
x = [0,1]
for i in range(n >> 1):
x[0] += x[1]
x[1] += x[0]
return x[n % 2]
Note! as a result, this simple algorithm only uses 1 assignment and 1 addition, since loop length is shorten as 1/2 and each loop includes 2 assignment and 2 additions.