Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.27 KB | None | 0 0
  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))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement