# Mathematics : Majic, Squared

**URL:** <https://boards.straightdope.com/t/mathematics-majic-squared/21865>\
**Category:** Factual Questions\
**Created:** [June 9, 2000, 12:43pm UTC](https://boards.straightdope.com/t/mathematics-majic-squared/21865 "2000-06-09T12:43:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![DougC](https://avatars.discourse-cdn.com/v4/letter/d/7feea3/32.png) [@DougC](https://boards.straightdope.com/u/DougC)\
**Post date:** [June 9, 2000, 12:43pm UTC](https://boards.straightdope.com/t/mathematics-majic-squared/21865/1 "2000-06-09T12:43:31Z")

</div>

- 
  - 
    - 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

---

<div class="post-metadata">

**Author:** ![John\_Kentzel-Griffin](https://avatars.discourse-cdn.com/v4/letter/j/ccd318/32.png) [@John\_Kentzel-Griffin](https://boards.straightdope.com/u/John_Kentzel-Griffin)\
**Post date:** [June 9, 2000, 1:31pm UTC](https://boards.straightdope.com/t/mathematics-majic-squared/21865/2 "2000-06-09T13:31:24Z")

</div>

> [@](#):
>
> **MC** asked:  
> (I)s 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?

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.

---

<div class="post-metadata">

**Author:** ![Achernar](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@Achernar](https://boards.straightdope.com/u/Achernar)\
**Post date:** [June 9, 2000, 1:37pm UTC](https://boards.straightdope.com/t/mathematics-majic-squared/21865/3 "2000-06-09T13:37:10Z")

</div>

Would you mind defining a “majic square”, or else providing an appropos link? The “magic square” oddity that I’m familiar with ([refernce](http://www.geocities.com/CapeCanaveral/Launchpad/4057/magicsquare.htm)) does not depend on the numerical base used. If this is what you’re talking about, I think you ought to rephrase your question.

---

<div class="post-metadata">

**Author:** ![Achernar](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@Achernar](https://boards.straightdope.com/u/Achernar)\
**Post date:** [June 9, 2000, 1:56pm UTC](https://boards.straightdope.com/t/mathematics-majic-squared/21865/4 "2000-06-09T13:56:57Z")

</div>

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):

```auto

  · · 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:

```auto

 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**.)

---

<div class="post-metadata">

**Author:** ![John\_Kentzel-Griffin](https://avatars.discourse-cdn.com/v4/letter/j/ccd318/32.png) [@John\_Kentzel-Griffin](https://boards.straightdope.com/u/John_Kentzel-Griffin)\
**Post date:** [June 11, 2000, 5:57pm UTC](https://boards.straightdope.com/t/mathematics-majic-squared/21865/5 "2000-06-11T17:57:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![knappy](https://avatars.discourse-cdn.com/v4/letter/k/b3f665/32.png) [@knappy](https://boards.straightdope.com/u/knappy)\
**Post date:** [June 12, 2000, 2:48pm UTC](https://boards.straightdope.com/t/mathematics-majic-squared/21865/6 "2000-06-12T14:48:31Z")

</div>

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}.

---

<div class="post-metadata">

**Author:** ![Achernar](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@Achernar](https://boards.straightdope.com/u/Achernar)\
**Post date:** [June 12, 2000, 3:46pm UTC](https://boards.straightdope.com/t/mathematics-majic-squared/21865/7 "2000-06-12T15:46:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![knappy](https://avatars.discourse-cdn.com/v4/letter/k/b3f665/32.png) [@knappy](https://boards.straightdope.com/u/knappy)\
**Post date:** [June 12, 2000, 7:47pm UTC](https://boards.straightdope.com/t/mathematics-majic-squared/21865/8 "2000-06-12T19:47:20Z")

</div>

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.
