Created
April 26, 2014 21:08
-
-
Save steventlamb/11331119 to your computer and use it in GitHub Desktop.
This file contains 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
def take_fib(i): | |
"returns the 1-indexed fibonacci number. so fib(1) == 0, fib(2) == 1, etc." | |
# 0 and 1 are special. Se | |
n1 = 0 | |
n2 = 1 | |
if i == 1: | |
return [n1] | |
else: | |
results = [n1, n2] | |
while i > 2: | |
n1, n2 = n2, n1 + n2 | |
i = i - 1 | |
results.append(n2) | |
return results | |
print take_fib(1000) | |
# with unix time: | |
# real 0m1.610s | |
# user 0m0.016s | |
# sys 0m0.004s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment