Created
June 15, 2012 22:26
-
-
Save lucassmagal/2938993 to your computer and use it in GitHub Desktop.
fibonacci
This file contains hidden or 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
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