Skip to content

Instantly share code, notes, and snippets.

@svvitale
Created November 7, 2017 05:59
Show Gist options
  • Save svvitale/0b68722de1e566f82f1cb593ba0345d0 to your computer and use it in GitHub Desktop.
Save svvitale/0b68722de1e566f82f1cb593ba0345d0 to your computer and use it in GitHub Desktop.
def fib_iterative(n):
sequence = (0, 1)
if n < 2:
return sequence[n]
for _ in range(n - 2):
sequence = (sequence[1], sequence[0] + sequence[1])
return sequence[0] + sequence[1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment