Collatz Conjecture


Python Day 4: Collatz Conjecture

Some of the students used to ask me, why do we have to learn calculus? I told them because if they are good at calculus then they may good at abstract algebra and number theory, and eventually can be the front page of the People’s Magazine like Andrew Wiles. (Andrew Wiles proved Fermat’s Last Theorem).


ractapopulous / Pixabay

There are still some unsolved maths conjectures that are easy to understand, For example, the Collatz Conjecture.

Collatz Conjecture:

  1. Take any natural number, n.
  2. If n is even, divide it by 2.
  3. Otherwise, n is odd. Multiply it by 3 and add 1
  4. Repeat indefinitely, the number will converges to 1 for finitely many steps.



Mathematicians could not find a counterexample, however, there is no formal proof for Collatz Conjecture.  Therefore the problem still remains unsolved. 

I wrote short python code to test the algorithm, the numbers I checked did converge to 1.

But, as my maths professor always says: 

“For example” is NOT a proof!


def collatz_conjecture(x):
    lists= [x]
    if x<1 :
        return []
    while x > 1:
        if x% 2==0:




[6, 3.0, 10.0, 5.0, 16.0, 8.0, 4.0, 2.0, 1.0]
[180,90.0,45.0, 136.0,68.0,34.0,17.0,52.0,26.0,13.0,40.0,20.0,10.0,5.0,16.0,8.0,4.0,2.0,1.0]


Note: the picture is from


Happy Studying! 🥨


Post navigation

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Social media & sharing icons powered by UltimatelySocial
%d bloggers like this: