Number Theory

The Collatz Sequence in Python

Learn how to write programs involving the Collatz Sequence!

Lin Jiang
The Art of Python
Published in
3 min readMar 10, 2021

--

Welcome back! In today’s article, we’ll be taking a look at the Collatz sequence. This article aims to explain the basic principles of the Collatz sequence and how to solve tasks involving it using Python programming.

What is the Collatz Sequence?

The Collatz Sequence is an actively studied sequence, particularly because of its relationship to the Collatz conjecture. Let’s first explain what the Collatz conjecture is, before diving into the specifics about the sequence.

The Collatz Conjecture

This particular conjecture has not been disproved or proved yet, so it remains a mathematical mystery in the world. The conjecture says the following:

The Collatz sequence will always eventually reach one, regardless of which positive integer is chosen initially.

In other words, no matter what the starting value is (as long as it is a positive integer), it will always reach 1 through the Collatz Sequence.

The Collatz Sequence

The Collatz sequence is actually very easy to understand. The sequence offers two…

--

--