Skip to content

Instantly share code, notes, and snippets.

@tmiz
Created October 18, 2011 07:23
Show Gist options
  • Save tmiz/1294810 to your computer and use it in GitHub Desktop.
Save tmiz/1294810 to your computer and use it in GitHub Desktop.
cached fib
cache_fib={}
def c_fib(n):
if cache_fib.has_key(n):
return cache_fib[n]
if n==0:
cache_fib[0]=0
elif n==1:
cache_fib[1]=1
else:
cache_fib[n] = c_fib(n-1)+c_fib(n-2)
return cache_fib[n]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment