Skip to content

Instantly share code, notes, and snippets.

@havenwood
Forked from HaniKazmi/ProjectEuler14
Created February 13, 2014 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save havenwood/8984010 to your computer and use it in GitHub Desktop.
Save havenwood/8984010 to your computer and use it in GitHub Desktop.
class Integer
def collatz_chain_size
n = self
chain = []
until n == 1
chain << n
n.even? ? n /= 2 : n = n * 3 + 1
end
[chain.size, chain.first]
end
end
1.upto(1_000_000).max_by &:collatz_chain_size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment