CJCoding With Joseph
15free / daySign inCreate account

Collatz Length

Read a positive whole number n and count how many values its Collatz sequence contains, counting n itself and the final 1: while n is not 1, replace it with n // 2 when it is even (test with the remainder operator %) and with 3 * n + 1 when it is odd, adding one to a counter on every step. Print Length: <count>. Input: one integer, no prompt. An input of 1 is already at the end, so its length is 1.

Expected Output:

Length: 10

= newline. The output ends with a newline — print one after the last line.

Hints3 available
Topics:
LoopsPractice Problems
📥 Auto-Input:
12\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.