Jonathan. Frech’s WebBlog

Collatz Conjecture (#140)

Jonathan Frech

The Collatz conjecture states that every positive integer 𝑘 > 0 will — if you iteratively set 𝑘 to 𝑓 (𝑘) — result in 1 (function shown beneath).
The graph beneath shows the path length of numbers from 1 to 10 000. In this range, 6 170 is the num­ber with the most steps, 261.

$$f(k)={\begin{cases}\frac{k}{2}&{\text{if }}k\mod 2=0\\3\cdot k+1&{\text{if }}k\mod 2=1\end{cases}}$$$$f(k)={\begin{cases}\frac{k}{2}&{\text{if }}k\mod 2=0\\3\cdot k+1&{\text{if }}k\mod 2=1\end{cases}}$$

Source code: collatz-conjecture.py