A small problem

64 divided by 16 equals 4. That’s how division works. But for the sake of a maths puzzle, let’s just cross out the digits in the numerator and denominator that are shared by both. In this case, we can cross out both 6’s and are left with 4/1 which also equals 4. The question is – what other numbers, apart from multiples of 10 and 1,  does this work for?

I decided rather than thinking of numbers randomly and testing them in my head, I’d get a computer to do it for me. I ended up spending a day writing a script that found all 416 solutions to the problem using numbers up to 3 digits long. It’s set up to do 4-digit numbers too, but processing time was a little long so I didn’t bother.

To jump ahead, here are a couple of nice solutions.

260 ÷ 65 = 4,

and when you cross out the 6’s, you get

20 ÷ 5 = 4.


95 ÷ 19 = 5      &      5 ÷ 1 = 5.

Here’s a folder you can download with the MATLAB scripts I wrote to find the solutions. mathsPuzzle.m is the main script to run, and cancelout.m is a function I made that is used in the main script, so both are needed. There’s also a .mat file with all solutions saved to a structure called BIG, which contains a field with all solutions, and a field with solutions that divide into a whole number.

I started with a single digit, 6, aiming to complete the process with just one number and then I can just substitute in the other digits. When I say digit here, I am referring to the digit that is going to be cancelled out. So just like in the first example, 6 was cancelled out in 64 ÷ 16. I needed to make a big matrix with all the numbers that contain a 6, and then divide every number in that matrix by all the numbers in that same matrix. And then I needed to take out the 6’s in every number in that matrix and repeat the process. And if the answer to both of those was the same, I had a hit.

The best way I could think to do this was to convert each number into a string, so I could separate the number 675 for example into a 6, a 7 and a 5. This was useful in two ways. Firstly it meant I could check if 675 contained a 6 in any of the three positions. And secondly, later on I could use it to make 675 into 75, and then make 160 into 10, just by deleting the digit in focus.

I made a matrix of all single, double, triple and quadruple digit numbers, for example:

mat3 = 100:999;

Then I ran a loop to (1) convert each number to a string, (2) check if each string contained a 6 in any position, and (3) add the numbers that contained 6 to a new matrix. For triple digit numbers this looked like:

Screenshot 2020-04-08 at 16.33.55.png

I then made a loop dividing every number by every other number in the matrix, and collected the solutions in a matrix of “normal solutions” which I called normSol. I also collected solutions to the other form of division where both the numerator and denominator had their 6’s cancelled out. The cancelled out solutions were stored in vertSol which was named as so for a reason I can’t remember. All I needed to do then was check if numbers in normSol matched vertSol, and keep track of the numerators and denominators in the process.

By the way, I quite like the use of the variable ‘triple’ in the loop above, where I effectively used it as a switch that was flipped as soon as the digit in focus was found. I set this equal to 0 at the start of every loop, and then if the first digit was equal to 6, it would set triple equal to 1. This meant that if the first digit was a 6, it wouldn’t bother checking the second and third digits, as the number would already have been added.

To do the cancelling out though, I wrote a function in a separate script to keep it as tidy as possible. I couldn’t think of shorter way of making 675 into 75 other than converting the number to a string, checking each digit, and then getting rid of any of the digits equal to 6. That means there were quite a few combinations I needed to write out. So for three digit numbers, if the first digit is a 6, the new number needs to be the second and third digits (75). But with 160, the new number needed to be first and third digits (10). For 656, the new number would only be the second digit, and if all digits were 6, I set the new number equal to 1 (rather than 0 which would result in dividing errors).

Screenshot 2020-04-08 at 16.52.56.png

What it meant though, was back in the main script, all I needed to write was…


…and I would get the answer 75. The function works for all numbers up to four digits long and displays a message if attempted for numbers longer than that.

I heard this maths puzzle on Radio 4’s Today programme on Thursday 19 March (I think – was definitely that week!).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s