Created
July 19, 2012 07:48
-
-
Save alanduan/3141433 to your computer and use it in GitHub Desktop.
Get the nth Fibonacci number.
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 f_simple_yet_stupid(n): | |
if n == 1 or n == 2: | |
return 1 | |
return f(n - 1) + f(n - 2) | |
def f(n): | |
a = [0, 0, 1] | |
for i in range(n - 1): | |
a[:2] = a[1:] | |
a[2] = a[0] + a[1] | |
return a[2] | |
import time | |
s = time.time() | |
print f(100000) | |
print time.time() - s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is also stupid. How about: