Created
November 7, 2017 05:59
-
-
Save svvitale/0b68722de1e566f82f1cb593ba0345d0 to your computer and use it in GitHub Desktop.
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_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