CJCoding With Joseph

Collatz Step Count

Read a positive integer n. Repeatedly apply the Collatz rule (if n is even, halve it; if odd, replace it with 3 * n + 1) counting how many steps it takes to reach 1, then print that count.

For input 6 the 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
๐Ÿ“ฅ Auto-Input:
6\n
This input is automatically fed to your program's stdin
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.