diff options
author | Braxton Hall | 2022-10-27 20:54:39 +0000 |
---|---|---|
committer | GitHub | 2022-10-27 20:54:39 +0000 |
commit | 3d3a66b5b4c23c5acd1dbde12957191e224849b1 (patch) | |
tree | d36a6b9387d69a49f57087532a0192ec6356b84c /entries/patricebelleville/fib.py | |
parent | 0c016d787b18f2e0ccba2892067e6ab0c4bb30ad (diff) | |
parent | 0c3a8d355afe70a3ba593fc3f1ead665abf5bb09 (diff) |
Merge branch 'main' into main
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) + |