Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def memoize(func):
- memory = {}
- def memoized(*args):
- if args in memory: return memory[args]
- result = func(*args)
- memory[args] = result
- return result
- return memoized
- def fib(x):
- if x in [0, 1]: return 1
- return fib(x - 1) + fib(x - 2)
- fib = memoize(fib)
- print(fib(33))
Add Comment
Please, Sign In to add comment