โ Back to Loops
Question 350
Collatz Step Count
Collatz Step Count
Read a positive integern. Repeatedly apply the Collatz rule (ifnis even, halve it; if odd, replace it with3 * n + 1) counting how many steps it takes to reach 1, then print that count. For input6the sequence is 6, 3, 10, 5, 16, 8, 4, 2, 1, which is 8 steps, so the output is: 8
Expected Output:
8
Topics:
Loops
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (cw, cr, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.