SHARE
TWEET

Untitled

a guest Oct 21st, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fib_cache = {}
  2.  
  3. def fibonacci(n):
  4.   if n in fib_cache:
  5.     return fib_cache[n]
  6.   if n == 1:
  7.     value = 1
  8.   elif n == 2:
  9.     value = 1
  10.   else:
  11.     value = fibonacci(n-1) + fibonacci(n-2)
  12.   fib_cache[n] = value
  13.   return value
  14.  
  15. for i in range(1, 500):
  16.   print(i, ": ", fibonacci(i))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top