Reference no: EM132218404
Pick a number, any number (actually, make it a positive integer). Now, let's play a game. If your number is even, divide it by 2. If it is odd, multiply it by 3 and add 1.
Repeat this process with your new number. Repeat over and over again. Lothar Collatz in 1937 guessed that this process will always eventually end at the number 1. This is now known as the Collatz conjecture.
Write MATLAB code that will start with a positive integer and run through this process until a 1 is reached. Have your code print to the screen the number of iterations necessary to reach 1. As a test, your code should report that 68 iterations are necessary if we start with the number 2017.
How many iterations are needed if we start with the following numbers?
26
27 (Why does 27 take so much longer than 26 and 28? Just one of those things.)
28
670, 617, 279 (this is the longest the process takes for any starting number less than 1 billion)