The collatz sequence goes like this:
For example, starting by 10
we have:
10 → 5 → 16 → 8 → 4 → 2 → 1
Write a function, named collatz_length
, given a number the function return
the length of the sequence before reaching 1, for example:
>>> collatz_length(10)
6
Because it takes 6 steps (6 →
in the previous example) to reach 1.
Have fun.
There's no corrections yet, hit the `Submit` button to send your code to the correction bot.
Keyboard shortcuts: