Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def memoize(f):
- t = dict()
- def lambda1(n):
- if n not in t:
- t[n] = f(n)
- return t[n]
- return lambda1
- fibfast = memoize(lambda n : 1 if n < 2 else fibfast(n-1) + fibfast(n-2))
- print(fibfast(1))
- print(fibfast(2))
- print(fibfast(3))
- print(fibfast(4))
- print(fibfast(5))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement