Created
April 18, 2013 01:23
-
-
Save abrongersma/5409179 to your computer and use it in GitHub Desktop.
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
| class Integer | |
| def fibonacci | |
| a, b = 0, 1 | |
| return self if self < 2 | |
| 2.upto(self) do | |
| a, b = b, a+b | |
| end | |
| b | |
| end | |
| end | |
| # How I walk most students through it: | |
| class Integer | |
| def fibonacci | |
| a, b = 0, 1 | |
| return self if self < 2 | |
| (0..self).each do | |
| c = a + b | |
| a = b | |
| b = c | |
| end | |
| a + b | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment