Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fib memo
CACHE = {0: 0, 1: 1}
def fib_memo(n):
if n not in CACHE:
print("Computing new value.")
CACHE[n] = fib_memo(n-1) + fib_memo(n-2)
print("Fetching value from cache.")
return CACHE[n]
start = 1
stop = 5
res = []
for i in range(start, stop+1):
res.append(fib_memo(i))
print(res)
res2 = []
for i in range(start, stop+1):
res2.append(fib_memo(i))
print(res2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.