Last active
August 29, 2015 14:03
-
-
Save JamesMcMahon/48a12f8a11f1601edaec to your computer and use it in GitHub Desktop.
Some days you just can't write a fibonacci generator, today is not that day
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
cache = {0: 0, 1: 1} | |
def fib(n): | |
if n in cache: | |
return cache[n] | |
f = fib(n - 1) + fib(n - 2) | |
cache[n] = f | |
return f | |
n = 100 | |
result = [fib(x) for x in range(n)] | |
print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment