Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/bash python
- from functools import wraps
- def memoize(obj):
- """Function wrapper for memorizing stuff."""
- cache = {}
- @wraps(obj)
- def memoizer(*args, **kwargs):
- """Actual memorizer."""
- if args not in cache:
- cache[args] = obj(*args, **kwargs)
- return cache[args]
- return memoizer
- @memoize
- def fib(n):
- """Return the fibonacci sequence."""
- if n < 2:
- return n
- else:
- return fib(n-1) + fib(n-2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement