Created
February 17, 2012 23:17
-
-
Save c4urself/1856073 to your computer and use it in GitHub Desktop.
Iterative fibonacci
This file contains hidden or 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 iterative(n): | |
| if n == 0 or n == 1: | |
| return n | |
| prev2 = 0 | |
| prev1 = 1 | |
| for index in xrange(2, n + 1): | |
| ivalue = prev1 + prev2 | |
| prev2 = prev1 | |
| prev1 = ivalue | |
| if index == n: | |
| return ivalue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment