Last active
December 11, 2015 16:59
-
-
Save mfpiccolo/4631733 to your computer and use it in GitHub Desktop.
Returns the corresponding number from the fibonacci sequence
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
class Integer | |
def fibonicci | |
a = 0 | |
b = 1 | |
if self == 1 | |
1 | |
elsif self == 0 | |
0 | |
elsif self > 1 | |
array1 = [0,1] | |
self.times {|x|array1 << array1[x] + array1[x+1]} | |
return array1[self] | |
end | |
end | |
end | |
puts "'#{12.fibonicci}' should equal '144'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment