It is conjectured that this sequence if finite for all N; in other words, the program will eventually stop no matter what the initial value of N. This has been verified for all values of N at least through one billion, but no general proof of termination has been found.
For any N, the length of the sequence printed by the program is called the cycle-length of N. For example, the cycle-length of 22 is 16. Your job is to write a program to compute the maximum cycle-length of any number within a specified range.
The input consists of one or more pairs (A,B) of nonnegative integers. Each pair of numbers is separated by a space and is on a line by itself. If A=0 it signals the end of the input. Otherwise, A will be less than or equal to B, and B will be at most 10,000. For each such pair your program must output the maximum cycle-length of any number between A and B, inclusive. Note that a brute-force approach will take too much time.
Input must be read from the file "prob23.in",
and output must be written to the file "prob23.out".
All output to the screen will be ignored.
<BOF> 100 200 900 1000 1 10 201 210 0 0 <EOF>
125 174 20 89
Dr. Eric Shade