Skip to content

Instantly share code, notes, and snippets.

@nikalras
Created April 24, 2016 04:27
Show Gist options
  • Save nikalras/60a6dd988a96e9aac36ebdf32e9a3641 to your computer and use it in GitHub Desktop.
Save nikalras/60a6dd988a96e9aac36ebdf32e9a3641 to your computer and use it in GitHub Desktop.
class mme(object):
def __init__(self,f):
self.f = f
self.d = {}
def __call__(self,arg):
if arg in self.d:
return self.d[arg]
else:
print '1'
self.d[arg] = self.f(arg)
return self.d[arg]
@mme
def fib(n):
if n<=2:
return n
else:
return fib(n-1)+fib(n-2)
for i in [11,8,2,5,10]:
print fib(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment