Python

Collatz Conjecture

A function that calculates the number steps needed to satisfy the collatz conjecture

The collatz conjecture is completed by halving a even number or multiplying a odd number by three then adding one. Repeating this for any number and the result will converge to 1.

This program will get a number from the user and execute this process. The steps needed to solve the conjecture is then returned. The number with the longest number of iterations of all the numbers at or below the user input number is also returned.

Example:

> python collatz.py

> Enter a number: 10

> You began with 10, and

> it took 6 steps to reach one (:

> Do you want to print the whole sequence(Y/N): y

> [5, 16, 8, 4, 2, 1]

> Of all the the numbers below or equal to 10, 9 has the

> longest total number of iterations before reaching one, taking 19 steps