Created
April 24, 2016 04:27
-
-
Save nikalras/60a6dd988a96e9aac36ebdf32e9a3641 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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