Skip to content

Instantly share code, notes, and snippets.

@lucassmagal
Created June 15, 2012 22:26
Show Gist options
  • Save lucassmagal/2938993 to your computer and use it in GitHub Desktop.
Save lucassmagal/2938993 to your computer and use it in GitHub Desktop.
fibonacci
def fibonacci(num):
def _fib(n, p0=0, p1=1):
if n == 0:
return p1
return _fib(n - 1, p1, p0 + p1)
return _fib(num)
# another way, without external function
def fib(num, p0=0, p1=1):
if n == 0:
return p1
return fib(num - 1, p1, p0 + p1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment