aboutsummaryrefslogtreecommitdiff
path: root/entries/patricebelleville/fib.py
blob: 767ce11569239768b0222402499b2fe8bf669ec2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
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)