The following iterative sequence is defined for the set of positive integers:
- n โ n/2 (n is even)
- n โ 3n + 1 (n is odd)
Using the rule above and starting with 13, we generate the following sequence:
13 โ 40 โ 20 โ 10 โ 5 โ 16 โ 8 โ 4 โ 2 โ 1
It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms. Although it has not been proved yet (Collatz Problem), it is thought that all starting numbers finish at 1.
Which starting number, under one million, produces the longest chain?
NOTE: Once the chain starts the terms are allowed to go above one million.
Real time: 8.741 s
User time: 8.470 s
Sys. time: 0.157 s
CPU share: 98.69 %
Exit code: 0