Collatz Conjecture
Problem Description​
Consider an algorithm that takes as input a positive integer . If is even, the algorithm divides it by two, and if is odd, the algorithm multiplies it by three and adds one. The algorithm repeats this until becomes one. Your task is to simulate the execution of the algorithm for a given value of .
For example, the sequence for is as follows:
Input​
- A single positive integer .
Output​
- A string that contains all values of during the algorithm, separated by a single arrow surrounded by spaces " -> ".
Constraints​
Example​
Input:
3Output:
3 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1Explanation:
Starting from 3, the sequence follows the rules: 3 is odd, so 3 * 3 + 1 = 10; 10 is even, so 10 / 2 = 5; and so on until it reaches 1.