Skip to content

Instantly share code, notes, and snippets.

@ayato-p
Created November 6, 2012 03:36
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 ayato-p/4022393 to your computer and use it in GitHub Desktop.
Save ayato-p/4022393 to your computer and use it in GitHub Desktop.
#! /usr/bin/ruby
def collatz(n)
print n.to_s+"\n"
if n%2 == 0
collatz(n/2)
elsif n != 1
collatz(n*3+1)
end
end
collatz(ARGV[0].to_i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment