15 Minute Code: Attempting to Solve an Unsolvable Mathematics Problem (The Collatz Conjecture)

Coding is a fantastic tool that can allow us to create enormous projects that take many hours to complete. However, there are plenty of opportunities within normal lessons to create and use simple coding skills to prove ideas and enhance students’ learning.

In today’s entry, we will be looking at how just 10 minutes of coding time can allow students to take their mathematics skills to new incredible levels. This activity is simple enough for the whole class to access, while having enough scale to really challenge your brightest students. Better yet, the only equipment required is a text editor e.g. Visual Studio Code).

Our focus today will be on something called the ‘Collatz Conjecture‘. Introduced in 1937 by Lothar Collatz, the conjecture suggests that any positive integer (no matter how large it is) will always result in an answer of 1 when following a specific sequence. To date, no-one has been able to prove or disprove this conjecture due to its sheer size. Mathematicians believe that the scale of this problem is simply too large to solve with our current mathematical understanding – which makes it a perfect task for those students who race through all their work to tackle.

The Collatz conjecture is quite possibly the simplest unsolved problem in mathematics — which is exactly what makes it so treacherously alluring.

Quantamagazine

The conjecture, also known as the 3n + 1 problem, follows a simple set or rules:

  • If the number is even, divide it by two.
  • If the number is odd, triple it and add one.
{\displaystyle f(n)={\begin{cases}{\frac {n}{2}}&{\text{if }}n\equiv 0{\pmod {2}}\\[4px]3n+1&{\text{if }}n\equiv 1{\pmod {2}}.\end{cases}}}
Modular Arithmetic.

Collatz states that any positive integer, regardless of size, will eventually return to a value of 1.

Starting at 79, it takes 35 steps to get to 1

The Code

As you can probably imagine, testing out larger numbers starts to become a real challenge. It can take tens or even hundreds of steps to run a single number through the process of halving and 3n+1ing.

This is where coding can be used to further a lesson and allow students to investigate much deeper. A few simple lines of Python code can automate the entire process, allowing students to enter a number and have it automatically checked in less than a second.

The Python Code to solve Collatz Conjecture example

The first step is to define a new function called “Collatz”. It doesn’t actually matter what your function is called, but choosing a name that is logical is a good habit to keep. This function will accept a number.

The code will use a while statement to keep running until our number reaches 1. An if statement tells the code to multiply our number by 3 and add 1 if it is odd. An else statement tells the code to divide our number by 2 if it is even.

Conclusion

In summary, by using a cleaver piece of Python Code, your students now have the ability to explore the furthest reaches of Collatz Conjecture. By automating the calculation process, more time can be spent looking for patterns within the numbers and testing new ideas.

Leave a Reply