Skip to content

Instantly share code, notes, and snippets.

@ravicious
Created February 25, 2010 20:09
Show Gist options
  • Select an option

  • Save ravicious/314977 to your computer and use it in GitHub Desktop.

Select an option

Save ravicious/314977 to your computer and use it in GitHub Desktop.
class Integer
def collatz
if self > 1
if self.even?
number = (self / 2)
else
number = (self * 3 + 1)
end
number.collatz
return number
end
end
end
~/code $ irb -r collatz.rb
>> 27.collatz
=> 82
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment