Skip to content

Instantly share code, notes, and snippets.

@yvan-sraka
Created November 29, 2020 19:31
Show Gist options
  • Save yvan-sraka/8f6d7b18b762888c0c1d99cb751d8b9d to your computer and use it in GitHub Desktop.
Save yvan-sraka/8f6d7b18b762888c0c1d99cb751d8b9d to your computer and use it in GitHub Desktop.
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