Collatz sequence algorithm.