2 log
= Logger
.new(STDERR)
3 log
.level
= Logger
::WARN
5 $chain_lengths = {1 => 1}
8 unless $chain_lengths.has_key
?(n
)
10 $chain_lengths[n
] = 1 + chain_length(n
/ 2)
12 $chain_lengths[n
] = 1 + chain_length(3 * n
+ 1)
18 longest_chain_start
= 1
19 1.upto(1000000) do |i
|
20 if chain_length(i
) > chain_length(longest_chain_start
)
21 longest_chain_start
= i
22 log
.info
{"Found new longest chain. Starts at #{i}, #{chain_length(i)} elements"}
24 log
.debug
{"#{i} has chain length #{chain_length(i)}"}
27 puts
"Longest chain starts at #{longest_chain_start}, with #{$chain_lengths[longest_chain_start]} elements"