Mathematics : Majic, Squared

      • How I got started on this is kinda complicated to explain, but is there some rule or axiom which demonstrates that for any base n numbering system, a majic square is possible in cases where the digits [except for that which represents zero] can be arranged in a square? I seem to recall seeing a majic triangle somewhere; do (any) rules apply similarly? Or is finding these things just simply a trial-and-error process? - MC

Uh… No. The property of being a magic square is not related to the base. It just so happens the numbers from one to nine can form a magic square. If you take the non-zero digits there are in base 5 (one to four) they can be arranged in a square, but cannot form a magic square.

Would you mind defining a “majic square”, or else providing an appropos link? The “magic square” oddity that I’m familiar with (refernce) does not depend on the numerical base used. If this is what you’re talking about, I think you ought to rephrase your question.

Geez, DrMatrix, you’re just too darn fast. Since you seem to have answered the first question, I’ll help with the second, “Or is finding these things just simply a trial-and-error process?” The answer for an n×n Magic Square, at least for odd n’s, is No. There is a simple algorithm for filling them out. Here goes:

Put a 1 in the center square on the top row. Now envision the square is like an Asteroids screen - if you go off the top, you come on the bottom, Et Cetera. Go one space up and to the right, and put a 2. Go one space up and to the right from there, and put a 3. Soon You’ll have a matrix like this (5×5 shown here):


  ·  ·  1  ·  ·
  ·  5  ·  ·  ·
  4  ·  ·  ·  ·
  ·  ·  ·  ·  3
  ·  ·  ·  2  ·

Now you can’t go on, because there’s already a 1 in the next space. When this happens, go down a square, and continue going up and to the right. Soon, you’ll fill out the whole thing:



 17 24  1  8 15
 23  5  7 14 16
  4  6 13 20 22
 10 12 19 21  3
 11 18 25  2  9

I believe that there are algorithms for finding n×n Magic Squares for even n’s, but they’re nowhere near as reliable and nowhere near as simple.

(I hope this is what you’re asking about, MC.)

I am just kicking myself. I missed the oportunity to call a rectangular array of numbers a matrix. D’oh.

You have presented the construction of a magic square very clearly, Achernar. However, I would propose a slight change to your example, as the main diagonals of the square are also supposed to have the same magic sum (65 in this case). Instead of starting with the numbers 1 thru 5 going up with a slope 1, have them go up with slope 2 (i.e., with knight moves).

Also, MC , a proof of why this method works does make use of base q numbering. For instance, starting with 0 - 24 written in base 5 in a ‘natural’ order:

00 01 02 03 04
10 11 12 13 14
20 21 22 23 24
30 31 32 33 34
40 41 42 43 44

Then perform the scrambling described by Achernar, except using slope 2:

00 23 41 14 32
11 34 02 20 43
22 40 13 31 04
33 01 24 42 10
44 12 30 03 21

What you’ve done is to apply a linear transformation represented by the matrix

1 1
2 3

That is, a transformation that sends 11 base 5 to position (1,0) and 23 base 5 to position (0,1). Then, all the rows, columns & diagonals are seen to have the magic sum 60 because they feature 0 - 4 in the ones place and the 5’s place. Having the broken diagonals all with the magic sum makes the square pandiagonal magic.

It’s pretty easy to show that a nonsingular n x n matrix whose columns are sets having distinct subset sums (mod q) (where q is prime), with the transformation interpreted as above, will produce a pandiagonal magic n-cube with edge length q. For example, in the above example, the subset sums of {1,3} (mod 5) are 0, 1, 3 & 4, corresponding to {}, {1}, {3} & {1,3}.

You clearly know more about this than I do, knappy, so forgive my impertinence, but both of the main diagonals of my Magic Square do sum to 65. It seems your method for producing a so-called pandiagonal Magic Square also makes the broken diagonals sum to the right nubmer, which is mondo cool. Just out of curiosity, for what sizes does this work? You show it work for a 5×5, but it clearly won’t work for a 3×3.

Oops; looks like I was the impertinent one. Your example was in fact a magic square.

Regarding the method described in my earlier post, it will produce pangiagonal magic squares for primes > 4, and also for odd composites whose factors are all > 4.

For pandiagonal n-cubes, it will produce them for primes > 2^n or odd composites all of whose factors are > 2^n.