Skip to content

Instantly share code, notes, and snippets.

@gjcourt
Created June 22, 2011 20:04
Show Gist options
  • Save gjcourt/1041004 to your computer and use it in GitHub Desktop.
Save gjcourt/1041004 to your computer and use it in GitHub Desktop.
Recursive and Iterative Fibonacci
# lines words bytes
# 5 17 102
def rfib(n):
if n == 0 or n == 1:
return 1
else:
return rfib(n-1) + rfib(n-2)
# 8 23 113
def ifib(n):
a = 0
b = 1
for _ in xrange(n):
c = b
b += a
a = c
return b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment