Collatz Revisted
------- --------
Consider the operation F(N) defined as:
F(N) = N/2 if N can be divided by 2
F(N) = N/3 if N can be divided by 3
F(N) = 5N + 1 otherwise
We conjecture that for any natural number N, applying
F repeatedly to any non-zero natural number will
eventually arrive at the number 1.
Thus
[1] F(5) = 26
[2] F(26) = 13
[3] F(13) = 66
[4] F(66) = 33
[5] F(33) = 11
[6] F(11) = 56
[7] F(56) = 28
[8] F(28) = 14
[9] F(14) = 7
[10] F(7) = 36
[11] F(36) = 18
[12] F(18) = 9
[13] F(9) = 3
[14] F(3) = 1
so F applied 14 times starting at 5 will get to 1.
The original Collatz Conjecture, named after Lothar
Collatz, who first proposed it in 1937, is for a
simpler F, and has never been proved or disproved.
Given N, you are to find the number of times F must be
applied starting at N to get to 1.
Input
-----
Input contains several test cases. For each test case
there is one input line containing N. Input ends with
an end of file.
All numbers N input will be such that applying F many
times to N will not generate a number above 10^9.
Output
------
For each test case, one line containing first N and then
the number of times F must be applied starting at N to
get to 1.
Sample Input
------ -----
1
2
3
4
5
6
7
8
9
10
100
1000
10000
100000
1000000
10000000
100000000
1000000000
Sample Output
------- ------
1 0
2 1
3 1
4 2
5 14
6 2
7 5
8 3
9 2
10 15
100 11
1000 28
10000 28
100000 55
1000000 44
10000000 90
100000000 55
1000000000 87
File: collatz2.txt
Authors: Tom Widland
Bob Walton
Date: Tue Oct 8 07:49:59 EDT 2019
The authors have placed this file in the public domain;
they make no warranty and accept no liability for this
file.