Skip to content

Instantly share code, notes, and snippets.

@JamesMcMahon
Last active August 29, 2015 14:03
Show Gist options
  • Save JamesMcMahon/48a12f8a11f1601edaec to your computer and use it in GitHub Desktop.
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
#!/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