Collatz Step Counter
PROIteration & LoopsWhile Loop
Condition-controlled Loop
The Collatz process starts with a positive integer `n` and repeats the following until `n` becomes 1:
- If `n` is even, replace it with `n` divided by 2.
- If `n` is odd, replace it with `3 * n + 1`.
Write a program that inputs a positive integer and outputs the number of steps needed to reach 1.
For example, 6 -> 3 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1 takes 8 steps. An input of 1 needs 0 steps.
Example Input
6
Example Output
8
0% (0 passed / 0 attempted)