Magic Squares (Part 1)

I was watching an episode of Penn and Teller Fool Us with my parents, if you haven’t watched this show, you really should. It’s extremely entertaining, though my girlfriend gets very upset that the show doesn’t tell you exactly how the trick is done.

In this episode, a magician by the name of Amazing Allison does a trick involving a magic square – you can see it here. When I saw it, I immediately wanted to know how it was done using mathematics.

A brief set-up: someone is asked for a number between 25 and 99, and then the performer creates a magic square, such that the rows and columns add up to the target number, and in addition a whole lot of other things add up to the target number, including the diagonals, each square of 4, etc. In my mind, there must be a formula for this, so I set out to find it.

Let us briefly consider a trivial solution: Suppose my target number is y, then a trivial solution for an n \times n magic square is for all entries to equal \frac{y}{n}. Of course, this is not a very interesting magic square, and quite easy to make! So let us improve this slightly by introducing a free variable – so now we have a target number y, and we fill in one box with our free variable x. The question is now, how will we find the remainder of our entries? Mathematically, this requires us to find n^{2} - 1 linearly independent conditions upon the entries of the square, then we chuck it into a matrix and find the reduced row echelon form, and whaboom we’re done. Easy, right? I tried this using a 4\times 4 magic square and it was surprisingly hard to find 15 linearly independent conditions! Here were all the conditions I added:

  1. All rows and columns must add to y
  2. Each diagonal must add to y
  3. The corners must add to y
  4. Each square of 4 blocks must add to y
  5. Each combination of non-corner exterior squares must add to y
  6. Diagonal alternating patterns through the square from top-down must add to y

and I was finally able to hit rank 15! The square yielded was as follows:


Now, this is a good start, but looking at it, it still isn’t very interesting!

Going forward there are a couple of conditions that we should impose on this, firstly that each entry should be positive and integer. This will admit a trivial solution only in the case where y is divisible by 4. It may be better suited to a linear programming style problem, however, due to the integrality constraints. This will be further explored in part 2.



Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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