fork download
  1. $switch = lambda { |x| [lambda { |x| x / 2 }, lambda { |x| x * 3 + 1}][x % 2].call(x)}
  2.  
  3. def f(x, n)
  4. if x != 1
  5. f($switch.call(x), n + 1)
  6. else
  7. return n
  8. end
  9. end
  10.  
  11. $length = 0
  12. (1..1000001).each do |n|
  13. len = f(n, 1)
  14. if len > $length
  15. $length = len
  16. puts len
  17. puts $length
  18. end
  19. end
Time limit exceeded #stdin #stdout 5s 11144KB
stdin
Standard input is empty
stdout
Standard output is empty