Skip to content

Instantly share code, notes, and snippets.

@cpdean
Created March 27, 2011 06:46
Show Gist options
  • Save cpdean/888994 to your computer and use it in GitHub Desktop.
Save cpdean/888994 to your computer and use it in GitHub Desktop.
line 28 is some bullshit
def fib(n):
if n in (0,1):
return n
else:
return fib(n-1) + fib(n-2)
def memoize(n):
cache = {}
def helper(x):
if x not in cache:
cache[x] = f(x)
return cache[x]
return helper
def regloop(x):
fib(0)
for bro in range(x):
print fib(bro)
def memoloop(x):
fib(0)
fib = memoize(fib)
for bro in range(x):
print fib(bro)
def main():
#memoloop(30)
regloop(30)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment