Skip to content

Instantly share code, notes, and snippets.

@IlianIliev
Created July 13, 2017 16:25
Show Gist options
  • Save IlianIliev/1c5bec1ba56bbde21698ae1e479a22cb to your computer and use it in GitHub Desktop.
Save IlianIliev/1c5bec1ba56bbde21698ae1e479a22cb to your computer and use it in GitHub Desktop.
Fibonacci without recursion
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