Skip to content

Instantly share code, notes, and snippets.

@mfpiccolo
Last active December 11, 2015 16:59
Show Gist options
  • Save mfpiccolo/4631733 to your computer and use it in GitHub Desktop.
Save mfpiccolo/4631733 to your computer and use it in GitHub Desktop.
Returns the corresponding number from the fibonacci sequence
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