Created
January 29, 2018 07:18
-
-
Save jaamaalxyz/65554b80fbd1fe21871a504e0c94322c to your computer and use it in GitHub Desktop.
fibonacciSeries created by JamalUddin - https://repl.it/@JamalUddin/fibonacciSeries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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