MCPcopy Create free account
hub / github.com/geekcomputers/Python / getFibonacciRecursive

Function getFibonacciRecursive

fibonacci.py:21–36  ·  view source on GitHub ↗

Calculate the fibonacci number at position n recursively

(n: int)

Source from the content-addressed store, hash-verified

19
20
21def getFibonacciRecursive(n: int) -> int:
22 """
23 Calculate the fibonacci number at position n recursively
24 """
25
26 a = 0
27 b = 1
28
29 def step(n: int) -> int:
30 nonlocal a, b
31 if n <= 0:
32 return a
33 a, b = b, a + b
34 return step(n - 1)
35
36 return step(n)
37
38
39def getFibonacciDynamic(n: int, fib: list) -> int:

Callers 1

Calls 1

stepFunction · 0.70

Tested by

no test coverage detected