-
-
Save mingchen/41e4152981d6c81c01b8 to your computer and use it in GitHub Desktop.
fibonacci number
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
#!/usr/bin/env python | |
# | |
# fibonacci number | |
# | |
# f(x) = f(x-1) + f(x-2) | |
# | |
def f(x): | |
if x == 0: | |
return 0; | |
if x == 1: | |
return 1 | |
elif x == 2: | |
return 2 | |
else: | |
return f(x-1) + f(x-2) | |
def main(): | |
for i in range(39): | |
print(f(i)), | |
if __name__ == '__main__': | |
main() | |
# | |
# output: | |
# 0 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 2178309 3524578 5702887 9227465 14930352 24157817 39088169 63245986 | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment