-
-
Save IlianIliev/1c5bec1ba56bbde21698ae1e479a22cb to your computer and use it in GitHub Desktop.
Fibonacci without recursion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fib(n, start_sequence=None): | |
if not start_sequence: | |
start_sequence = [0, 1] | |
res = 0 | |
for i in range(0, n-1): # -1 to as we count the start sequence as the first two numbers | |
res = sum(start_sequence) | |
start_sequence.pop(0) | |
start_sequence.append(res) | |
print(res) | |
assert fib(11) == 89 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment