Skip to content

Instantly share code, notes, and snippets.

@eiszfuchs
Created July 7, 2010 14:29
Show Gist options
  • Save eiszfuchs/466763 to your computer and use it in GitHub Desktop.
Save eiszfuchs/466763 to your computer and use it in GitHub Desktop.
# http://en.wikipedia.org/wiki/Collatz_conjecture
def collatz(n)
seq = Array.new
while n > 1
if n%2 > 0
n = 3*n + 1
else
n = n / 2
end #if
seq.push n
end #while
return seq
end #def
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment