Created
July 8, 2015 12:12
-
-
Save igaiga/dfcc4c0b10d1e1241e37 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 Fibo | |
def calc(n) | |
a = 0 | |
b = 1 | |
return [1] if n == 1 | |
result = [1] | |
while a + b <= n | |
result << a + b | |
a = result[-2] | |
b = result[-1] | |
end | |
result | |
end | |
end | |
p Fibo.new.calc(100) #=> [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment