xsnippet logotype

xsnippet

#362507, Untitled [ Python 3 ]

by Guest
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
import functools


@functools.lru_cache()
def fib(n):
    if n < 2:
        return 1
    else:
        return fib(n - 1) + fib(n - 2)


def fib_tail(n, a=1, b=1):
    if n < 2:
        return a
    else:
        return fib_tail(n - 1, a + b, a)