  A very long time ago, 4000 years or more, China was being plagued by a great flood. People offered sacrifices to the river Lo, in order to appease it, but to no avail. The river’s only response was a turtle that emerged every time an offering was made. Then one day a little boy noticed some strange markings on the turtle’s back. They were representations of the numbers 1 through 9 arranged in a square. The four even numbers were in the corners of the square and the five odd ones formed the central cross:

Markings on the turtle’s back, above, representing the numbers shown below. [Images from Wikimedia Commons]

What could this mean? The boy realised that adding the numbers in any row, any column or any of the two diagonals always gave the same answer, 15. This, people concluded, told them how much they should be offering to the river.

This is legend but the centre piece, the Lo Shu magic square, is a very real piece of maths. A magic square is a square grid of whole numbers in which every row, column and diagonal adds up to the same magic number. There are 32=9 numbers in a square made up of three rows and columns, 42=16 numbers in a square with four rows and columns and, more generally, n2 numbers in a square with n rows and columns. A magic square that, like the Lo Shu square, contains exactly the first n2 numbers is called a normal magic square. The Lo Shu square is the smallest normal magic square (there aren’t any 2×2 ones) and it is the only 3×3 normal magic square, up to the fact that you could of course rotate or reflect it. As you increase the size of your square, possibilities multiply at break neck speed. There are 880 distinct 4×4 magic squares (excluding the various squares you get from rotating or reflecting a given square) and 275,305,224 5×5 magic squares. Nobody knows how many distinct 6×6 magic squares there are, but the number is estimated to be more than a million million million.

Considering these vast numbers it is perhaps surprising that all normal magic squares of a given size come with the same magic number. And it is easy to work out what this number is. An nxn normal magic square has n rows, each adding up to the magic number, which we can write as M(n). Adding up all the row totals we get nM(n). This is the sum of all the numbers in the square. But we also know that this sum is equal to 1+2+3 … + n2, since the square contains all the numbers from 1 to n2. So

nM(n) = 1+2+3 … + n2.

As you can see in the article on triangular numbers, the sum of the first n2 whole numbers is equal to n2 (n2+1)/2, which gives

nM(n) = n2 (n2+1)/2.

Dividing both sides by n gives us the value of M(n):

M(n) = n(n2+1)/2.

This tallies with what we already know about the Lo Shu magic square: substituting n=3 gives

M(3) = 3×10/2=15.

Magic squares have entertained mathematicians for millennia, but there is a related type of square that is the focus of contemporary fascination: the Latin square. An nxn Latin square contains the first n whole numbers, each of which is only allowed to appear once in every row and column. Every day millions of people travelling on thousands of trains around the world are struggling to find special 9×9 Latin squares: they are solving sudoku puzzles, which come with the extra restriction that the numbers 1 through 9 must appear exactly once in each of the nine 3×3 sub-boxes. As with magic squares the number of Latin squares explodes as they become bigger, there are

99,824,37,658,213,039,871,725,064,756,920,320,000

10×10 Latin squares, and there is no easy formula for computing the number of nxn Latin squares in general. But Latin squares are incredibly useful. Suppose, for example, you are organising a speed dating event with n women and n men. You want every man to meet every woman for exactly one minute in n time slots. One way of solving the problem is to create a square in which each column represents a woman and each row represents a man. Now label the time slots 1 through n and find an nxn Latin square with entries corresponding to time slots. Because every slot appears exactly once in each row and column there are no clashes: nobody is required to see two different people at the same time. And the fact that every cell in the grid is filled means that every woman gets to meet every man and vice versa. And it’s not just speed dating of course, Latin squares are useful in many, much more serious, time-tabling problems.

And what about sudoku? If you are an enthusiast you will be glad to hear that there are a total of 6,670,903,752,021,072,936,960 possible completed sudoku grids, so your supply is unlikely to run out any time soon. Of course everything depends on the number of clues you are given to start with: too many and it’s too easy, too few and it’s too hard and there may even be more than one solution. This has led mathematicians to wonder what is the minimal number of clues you need for the usual 9×9 sudoku to make sure there is only one solution given those clues. It took them quite some time to work this out, but the answer finally came in 2012: it’s 17. Their approach wasn’t particularly elegant. They used an exhaustive computer search to verify the result and the effort took almost one year of computing time.

The answer to the converse question — how many minimal clue sudokus are there that have a given grid as its solution — is still unknown. These curious squares still pose challenges, not only for commuters but also for mathematicians.