Created
November 29, 2020 19:31
-
-
Save yvan-sraka/8f6d7b18b762888c0c1d99cb751d8b9d to your computer and use it in GitHub Desktop.
This file contains 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
import functools | |
def memoization(f): | |
cache = {} | |
def func_wrapper(n): | |
if n not in cache: | |
result = f(n) | |
cache[n] = result | |
return cache[n] | |
return func_wrapper | |
#@functools.lru_cache(maxsize=None) | |
@memoization | |
def fibo(n): | |
if n < 2: | |
return 1 | |
return fibo(n - 1) + fibo(n - 2) | |
for i in range(100): | |
print("fibo(%d) = %d" % (i, fibo(i))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment