Practice · 5 of 5
Collatz Steps
CHALLENGE
Difficulty: intermediate+25 XP
**Description:** Starting from n, repeatedly: if n is even, n -> n/2; if odd,
n -> 3n + 1. The sequence reaches 1 for every tested input. Count the steps
**recursively** to reach 1 (a starting n of 1 is 0 steps).
**Input:** One line: n (1 <= n <= 10^6).
**Output:** One integer — the number of steps to reach 1.
**Example:** 6 -> 8 (6 3 10 5 16 8 4 2 1).
Press Submit to check your solution.
Back to lesson: Practice: Recursion Problem Set