Skip to content

Instantly share code, notes, and snippets.

@nickyfoto
Created April 25, 2019 15:01
Show Gist options
  • Save nickyfoto/455b87ca3bcaefd710e8b3d18863da77 to your computer and use it in GitHub Desktop.
Save nickyfoto/455b87ca3bcaefd710e8b3d18863da77 to your computer and use it in GitHub Desktop.
Calculate nth Fibonacci number using memoization
def fibM(n, d={0: 0, 1: 1}):
"""Memoization Fib"""
if n-2 in d and n-1 in d:
return d[n-2] + d[n-1]
else:
d[n-1] = d[n-3] + d[n-2]
return fibM(n-1, d)
fib(25)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment