Skip to content

Instantly share code, notes, and snippets.

@hillscottc
Created May 30, 2014 15:52
Show Gist options
  • Save hillscottc/a2c5dec8512a96ac60b9 to your computer and use it in GitHub Desktop.
Save hillscottc/a2c5dec8512a96ac60b9 to your computer and use it in GitHub Desktop.
Fibonacci, basic memoization.
fib_vals = {1:1, 2:1}
def fib(n):
if n <= 2:
return 1
if n in fib_vals:
return fib_vals[n]
else:
fib_vals[n] = fib(n - 1) + fib(n - 2)
return fib_vals[n]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment