aboutsummaryrefslogtreecommitdiff
path: root/entries
diff options
context:
space:
mode:
authorbraxtonhall2022-10-27 20:43:38 +0000
committerbraxtonhall2022-10-27 20:43:38 +0000
commit325e5393df36cb19bc87742f86ecdad0049b5fb9 (patch)
tree76026fb0788b0571c6080679fb23ddbec7d2be32 /entries
parenteea4d18a2ef4cfe4e5f4d4a302b6ef452dec18b7 (diff)
Add Patrice
Diffstat (limited to 'entries')
-rw-r--r--entries/patricebelleville/fib.py13
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)
+