$switch = lambda { |x| [lambda { |x| x / 2 }, lambda { |x| x * 3 + 1}][x % 2].call(x)}
def f(x, n)
if x != 1
f($switch.call(x), n + 1)
else
return n
end
end
$length = 0
(1..1000001).each do |n|
len = f(n, 1)
if len > $length
$length = len
puts len
puts $length
end
end
JHN3aXRjaCA9IGxhbWJkYSB7IHx4fCBbbGFtYmRhIHsgfHh8IHggLyAyIH0sIGxhbWJkYSB7IHx4fCB4ICogMyArIDF9XVt4ICUgMl0uY2FsbCh4KX0KCmRlZiBmKHgsIG4pCiAgICAgICAgaWYgeCAhPSAxCiAgICAgICAgICAgICAgICBmKCRzd2l0Y2guY2FsbCh4KSwgbiArIDEpCiAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgcmV0dXJuIG4KICAgICAgICBlbmQKZW5kCgokbGVuZ3RoID0gMAooMS4uMTAwMDAwMSkuZWFjaCBkbyB8bnwKICAgICAgICBsZW4gPSBmKG4sIDEpCiAgICAgICAgaWYgbGVuID4gJGxlbmd0aAogICAgICAgICAgICAgICAgJGxlbmd0aCA9IGxlbgogICAgICAgICAgICAgICAgcHV0cyBsZW4KICAgICAgICAgICAgICAgIHB1dHMgJGxlbmd0aAogICAgICAgIGVuZAplbmQ=