Created
June 22, 2011 20:04
-
-
Save gjcourt/1041004 to your computer and use it in GitHub Desktop.
Recursive and Iterative Fibonacci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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