Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

A Magic Square of order n is an arrangement of $n^2$ numbers, usually distinct integers, in a square, such that the n numbers in all rows, all columns, and both diagonals sum to the same constant.

To construct Magic Squares of n-odd size, a method known as Siamese method is given on Wikipedia, the method is ::

starting from the central box of the first row with the number 1 (or
the first number of any arithmetic progression), the fundamental 
movement for filling the boxes is diagonally up and right (↗), one step
at a time. When a move would leave the square, it is wrapped around to 
the last row or first column, respectively.

If a filled box is encountered, one moves vertically down one box (↓)    
instead, then continuing as before.

enter image description here

How does this method work?

share|cite|improve this question
up vote 2 down vote accepted

There is a detailed discussion of "the Siamese method," with proofs, at this website. There's also a proof here.

share|cite|improve this answer

The basic idea is that you divide the numbers from $1$ to $n^2$ into blocks $(1,n), (n+1,2n), (2n+1,3n) \ldots (n^2-n+1,n^2)$ and think of them as $0+(1,n), n+(1,n), 2n+(1,n) \ldots n(n-1)+(1,n)$. Then you want each row to get each of $(1,n)$ and each column to get each of $(1,n)$. The various runs of $n$ numbers start one in each row and each column, so they each go one per row and column. Each multiple of $n$ also goes one per row and column. It is a Greco-Latin square, if you make the Greek letters correspond to $(1,n)$ and the Latin letters correspond to $(0,(n-1)n)$

share|cite|improve this answer
It's not clear to me how this relates to the specific algorithm OP asks about. – Gerry Myerson Jul 27 '12 at 0:44
@GerryMyerson: I was hoping to explain that the diagonal movement distributes the numbers properly to ensure that each row and column get a number $1 \pmod n, 2 \pmod n 3 \pmod n \ldots 0 \pmod n$ and also a number in each bracket of $n$ numbers. Maybe it didn't come through. The site you cited looks very good. – Ross Millikan Jul 27 '12 at 1:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.