Skip to content

Instantly share code, notes, and snippets.

@c4urself
Created February 17, 2012 23:17
Show Gist options
  • Select an option

  • Save c4urself/1856073 to your computer and use it in GitHub Desktop.

Select an option

Save c4urself/1856073 to your computer and use it in GitHub Desktop.
Iterative fibonacci
def iterative(n):
if n == 0 or n == 1:
return n
prev2 = 0
prev1 = 1
for index in xrange(2, n + 1):
ivalue = prev1 + prev2
prev2 = prev1
prev1 = ivalue
if index == n:
return ivalue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment