[Algorithm] Ma methods – Magic square

In math fun, Magic matrix of degree n (also known as ma or the magic square) an arrangement of n², usually distinct integers, in a square table so that the total number in each row n, post, and diagonals are equal standard dental Magic square contains the integers from 1 to n².

Magic exists matrix standard for all orders n ≥ 1 except n = 2. Magic square Career 1 the trivial case, it contains only 1 cell value 1. In case of non-trivial size is the smallest rank matrix Magic 3.

The constant is the sum of each row, post, and diagonal called Magic constants. The value of the standard matrix miraculous depends only on n and valuable

M = frac{n(n^2+1)}{2}.

With the Magic matrix rank n = 3, 4, 5, ..., Magic constants respectively: 15, 34, 65, 111, 175, 260, ...

How to set the retail Ma:
Draw a square of the grid to the inside of the line and column numbers as the ghost dish set. Then draw from the grid side 4 follow me cry tower next to a sub-image. Then you hit a row of squares on the diagonal of this new. Then move the number of squares on the side on the main square in which the outer side of left empty squares opposite outer side of the main square.
Such a ghost at the level 5

ma methods

A ghost is much more explanation for it, such as the level ma 3
ma methods

Ma methods have 2 kind: ma ma methods and even the odd:

How to set the retail Ma:

Number 1 always write in the box in the middle of the line 1.
When the arrow goes out 1 edge would go to the opposite side to the other (see round blue and red ring)
When the arrow on the top right corner to meet (here is the cell containing the number 15) it will run down box located below (Round green)
When the arrow met 1 cell number which then (Round yellow, cell containing the number 1) it will go down box located right duoi.Cu like until all the cells in ma.

ma phuong

How to set the parity Ma:

In general, the more complex the odd ghost and we split them up 2 ma is the kind of level 4n (n >= 1) and level 4n + 2 (n >= 1).
For ma local level, only 4n squares divided into small groups with each group 4 current, 4 post. Draw all the main diagonal of the small group. Then, we proceed numbered from left to right, from top to bottom of the box located on the diagonal.
ma methods

Then we re-numbered from right to left, from bottom to top for the remaining cells.
ma methods

Article referenced in: mathvn.com