Can you make it fast?
See Wikipedia.
Compute the length of all Collatz paths for numbers 2 to N as fast as possible. Some example lengths:
Number | Path length |
---|---|
2 | 1 |
3 | 7 |
4 | 2 |
5 | 5 |
6 | 8 |
If you need an example program, have a look at this file.
collatz(x):
if x % 2 == 0:
return x / 2
else:
return x*3 + 1
- Calculate all Collatz paths for 2 to N
- Your program's first argument must be N
For testing purposes, run