Skip to content

Instantly share code, notes, and snippets.

@aereal
Created January 18, 2011 12:08
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 aereal/784343 to your computer and use it in GitHub Desktop.
Save aereal/784343 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
def collatz(n)
n == 0 || n == 1 ? n : n.even? ? collatz n / 2 : collatz n * 3 + 1
end
1.upto(3 * 2 ** 52).all? {|i| collatz(i) == 1 } # -> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment