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:
- Take any natural number, n.
- If n is even, divide it by 2.
- Otherwise, n is odd. Multiply it by 3 and add 1
- 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: x=x/2 else: x=x*3+1 lists.append(x) return(lists) collatz_conjecture(6) collatz_conjecture(93) collatz_conjecture(180)
Output: