Last active
August 29, 2015 14:01
-
-
Save johannes-scharlach/6fc65eab5ee41cfa7c38 to your computer and use it in GitHub Desktop.
Python Fibonacci function
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
def fibonacci(n, a=-1, b=1): | |
return [a, b] if n==0 else fibonacci(n+(n<0)-(n>0), b-a*(n<0), a+b*(n>0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Short Python implementation of the fibonacci numbers for positive and negative
n
. Usage to get the Fibonacci number of any (positive or negative)n
: