Skip to content

Instantly share code, notes, and snippets.

@steventlamb
Created April 26, 2014 21:08
Show Gist options
  • Save steventlamb/11331119 to your computer and use it in GitHub Desktop.
Save steventlamb/11331119 to your computer and use it in GitHub Desktop.
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