Created
November 1, 2017 10:40
-
-
Save basnijholt/919610eb405b21c9579c49699a0efe84 to your computer and use it in GitHub Desktop.
Fibonacci with memoizing
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
from functools import lru_cache | |
@lru_cache() | |
def fib(n): | |
if n in [0, 1]: | |
return 1 | |
else: | |
return fib(n-1) + fib(n-2) | |
fib(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment