#214 · Loops · Beginner · 30 XP · about 5 min
Pick any positive whole number and apply this rule to it again and again:
Nobody has ever proved it, but every number anyone has tried eventually reaches 1. Write collatz_steps(n) that returns how many times the rule is applied before n reaches 1.
collatz_steps(6) # returns 8 collatz_steps(1) # returns 0 collatz_steps(7) # returns 16
From 6 the numbers are 6, 3, 10, 5, 16, 8, 4, 2, 1: that is 8 steps. If n is already 1, no steps are needed.
1 <= n <= 10 ** 13First solves only, ranked by stars and then time.