Skip to content

Instantly share code, notes, and snippets.

@abrongersma
Created April 18, 2013 01:23
Show Gist options
  • Select an option

  • Save abrongersma/5409179 to your computer and use it in GitHub Desktop.

Select an option

Save abrongersma/5409179 to your computer and use it in GitHub Desktop.
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