2020年10月12日月曜日

Collatz problem

Every positive integer except for zero includes 1. This is apparent 5*1=5. Therefore, every positive integer must be reduced to 1. This is called Collatz problem.
When you have even numbers, you divide them by 2. Then if the integer is the even number, you divide it by 2. However, 10/2 is 5. In this case, you have odd numbers, so you multiply 3 to them and you plus 1 to it. You repeat over and over again, until you reach to 1.


ex.

18/2=9, 9*3+1=28, 28/2=14, 14/2=7, 7*3+1=22, 22/2=11, 11*3+1=34, 34/2=17, 17*3+1=52, 52/2=26, 26/2=13, 13*3+1=40, 40/2=20, 20/2=10, 10/2=5, 5*3+1=16, 16/2=8, 8/2=4, 4/2=2, 2/2=1



0 件のコメント: