module Hailstone
  module_function
  def hailstone n
    seq = [n]
    until n == 1
      n = (n.even?)? (n / 2): (3 * n + 1)
      seq << n
    end
    seq
  end
end

if __FILE__ == $0
  include Hailstone

  
  hs27 = hailstone 27
  p [hs27.length, hs27[0..3], hs27[-4..-1]]

  
  n, len = (1 ... 100_000) .collect {|n|
    [n, hailstone(n).length]} .max_by {|n, len| len}
  puts 
  puts 
end