3x+1 recreated in Python

If a number is odd it is multiplied by 3 and 1 is added to the product. If a number is even it is divided by 2.

These rules are applied directly to any positive natural number. All numbers till 2 to the power 62 have been found and all end up at 1.

Since 1 is odd multiplying by 3 and adding 1 becomes 4, dividing by 2 gives 2, and dividing again gives 1, which creates a loop.

This Python code uses Matplotlib to show the graph of any number inputed.


View Github