Skip to content

Instantly share code, notes, and snippets.

@jaamaalxyz
Created January 29, 2018 07:18
Show Gist options
  • Save jaamaalxyz/65554b80fbd1fe21871a504e0c94322c to your computer and use it in GitHub Desktop.
Save jaamaalxyz/65554b80fbd1fe21871a504e0c94322c to your computer and use it in GitHub Desktop.
fibonacciSeries created by JamalUddin - https://repl.it/@JamalUddin/fibonacciSeries
# Fibonacci series using mem cache for effiecient solution
# Author: Jamal Uddin
# Date: 29.01.2018
def fib(n, _cache={}):
if n in _cache:
return _cache[n]
elif n > 1:
return _cache.setdefault(n, fib(n - 1) + fib(n - 2))
return n
series = []
for i in range(10):
series.append(fib(i))
print(series)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment