Longest Collatz sequence
Created on Jan. 18, 2017 by Julien Palard
The collatz sequence goes like this:
- Start by any number greater than zero.
- If your number is even, divide it by two.
- If your number os odd, multiply by three and add one.
For example, starting by 10
we have:
1 |
|
Write a function, named collatz_length
, given a number the function return
the length of the sequence before reaching 1, for example:
1 2 |
|
Because it takes 6 steps (6 →
in the previous example) to reach 1.
Advice
Have fun.
There's no corrections yet, hit the `Submit` button to send your code to the correction bot.
Keyboard shortcuts:
- Ctrl-Enter: Send your code to the correction bot.
- Escape: Get back to the instructions tab.