Foundations & earlier writing · January 2nd, 2018

Magic Squares

Today, we're going to explore a strange but (I think) fun oddity in discrete math called a magic square. These guys show up in all kinds of places and have a tangential relationship to the popular game Sudoku and the original strategy game, chess.

A Little Background

Magic squares have a long history in math. The basic definition of a magic square is a n * n grid containing integers that (a) do not repeat and (b) the sum of every row, column, and diagonal is the same value.

Here's an example

| 1 | 6 | 5 |
| 8 | 4 | 0 |
| 3 | 2 | 7 |

So, if we constructed that magic square correctly, we should find a constant of 12 for every row, column, and diagonal.

This is a normal magic square. Now, we can also have a magic square that has the magic constant of 15.

That is, a magic constant is the value of the row, column, and diagonal sums albeit in a special way. There's actually a neat little equation we can use to determine the magic constant of any size grid (yes, magic squares do not have to be 3 by 3 or what we call order 3). Check it out:

M = n(n^2 + 1)/2 where M is the magic constant.

Thus, we should compute 15 for an order 3 magic square. Can you compute the magic constant for an order 4?

There has been a ton of research into magic constants in the scope of magic squares. These guys are actually strong examples for algorithm development in undergraduate coursework. Furthermore, in case you're wondering, yes a magic square can contain negative integers.

For example:

| -4 | 1 | 0 |
| 3 | -4 | -5 |
| -2 | -3 | 2 |

The constant for this normal magic square is -3, correct? Yep, neat.

Conclusion

These short blog posts are intended to promote fields of study that I find interesting. If you like this type of blog content, please send me a tweet. If you don't like this type of content, send me a tweet with a suggestion on what content would be better.

← Back to essays