MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / simple_fibonacci

Function simple_fibonacci

maths/matrix_exponentiation.py:67–95  ·  view source on GitHub ↗

Returns the nth number of the Fibonacci sequence that starts with f1 and f2 Uses the definition >>> simple_fibonacci(1, 5, 6) 5 >>> simple_fibonacci(2, 10, 11) 11 >>> simple_fibonacci(13, 0, 1) 144 >>> simple_fibonacci(10, 5, 9) 411 >>> simple_fibonac

(n: int, f1: int, f2: int)

Source from the content-addressed store, hash-verified

65
66
67def simple_fibonacci(n: int, f1: int, f2: int) -> int:
68 """
69 Returns the nth number of the Fibonacci sequence that
70 starts with f1 and f2
71 Uses the definition
72 >>> simple_fibonacci(1, 5, 6)
73 5
74 >>> simple_fibonacci(2, 10, 11)
75 11
76 >>> simple_fibonacci(13, 0, 1)
77 144
78 >>> simple_fibonacci(10, 5, 9)
79 411
80 >>> simple_fibonacci(9, 2, 3)
81 89
82 """
83 # Trivial Cases
84 if n == 1:
85 return f1
86 elif n == 2:
87 return f2
88
89 n -= 2
90
91 while n > 0:
92 f2, f1 = f1 + f2, f2
93 n -= 1
94
95 return f2
96
97
98def matrix_exponentiation_time() -> float:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected