diff options
author | Braxton Hall | 2022-10-27 20:50:22 +0000 |
---|---|---|
committer | GitHub | 2022-10-27 20:50:22 +0000 |
commit | 2310fb9265692aee5b06e2f35830b8ceca193073 (patch) | |
tree | 76026fb0788b0571c6080679fb23ddbec7d2be32 /entries/patricebelleville/fib.py | |
parent | eea4d18a2ef4cfe4e5f4d4a302b6ef452dec18b7 (diff) | |
parent | 325e5393df36cb19bc87742f86ecdad0049b5fb9 (diff) |
Merge pull request #59 from braxtonhall/patrice
Add Patrice Belleville
Diffstat (limited to 'entries/patricebelleville/fib.py')
-rw-r--r-- | entries/patricebelleville/fib.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/entries/patricebelleville/fib.py b/entries/patricebelleville/fib.py new file mode 100644 index 0000000..767ce11 --- /dev/null +++ b/entries/patricebelleville/fib.py @@ -0,0 +1,13 @@ +def fibonacci(n): + return fib_helper(n, 0, 1) + +def fib_helper(n, prev, curr): + # Base cases + if n < 0: + raise ValueError('Negative argument to fibonnaci') + if n == 0: + return prev + if n == 1: + return curr + return fib_helper(n-1, curr, prev + curr) + |