Skip to content

Instantly share code, notes, and snippets.

@abhi923
Created June 8, 2020 09:49
Show Gist options
  • Save abhi923/fa4dab6e9520661adecc0e35a8c1333d to your computer and use it in GitHub Desktop.
Save abhi923/fa4dab6e9520661adecc0e35a8c1333d to your computer and use it in GitHub Desktop.
def fib(n):
if n < 1:
return None
if n < 3:
return 1
elem1 = elem2 = 1
sum = 0
for i in range(3, n + 1):
sum = elem1 + elem2
elem1, elem2 = elem2, sum
return sum
for n in range(1, 10): # testing
print('fib', n, "->", fib(n))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment