aboutsummaryrefslogtreecommitdiff
path: root/entries/patricebelleville
diff options
context:
space:
mode:
Diffstat (limited to 'entries/patricebelleville')
-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)
+