From 325e5393df36cb19bc87742f86ecdad0049b5fb9 Mon Sep 17 00:00:00 2001 From: braxtonhall Date: Thu, 27 Oct 2022 13:43:38 -0700 Subject: Add Patrice --- entries/patricebelleville/fib.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 entries/patricebelleville/fib.py (limited to 'entries/patricebelleville') 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) + -- cgit v1.2.3-70-g09d2