Skip to content

Instantly share code, notes, and snippets.

@gauravvjn
Created May 31, 2018 06:44
Show Gist options
  • Save gauravvjn/99d64b9d4d480af459bacfeba877f25e to your computer and use it in GitHub Desktop.
Save gauravvjn/99d64b9d4d480af459bacfeba877f25e to your computer and use it in GitHub Desktop.
Get a list of N fibonacci numbers using tail recursion
"""
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