Created
May 31, 2018 06:44
-
-
Save gauravvjn/99d64b9d4d480af459bacfeba877f25e to your computer and use it in GitHub Desktop.
Get a list of N fibonacci numbers using tail recursion
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 Number list using tail recursion | |
""" | |
def fib_list(n, a, b, r): | |
if n == 0: return [1] | |
elif n < 0: return [] | |
r.append(a + b) | |
fib(n-1, b, a + b, r) | |
return r | |
N = 5 | |
print(fib_list(N - 1, 0, 1, [1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment