### Puzzle of putting numbers 1-9 in 3x3 Grid to add up to 15

• Freya

6 years ago

In a 3x3 grid, I'd have to put numbers from 1 to 9 in a manner so that respective row, column and diagonal add up to 15.

I have only been able to come up with one solution:

$$\begin{array}{ccc} 6 & 1 & 8 \\ 7 & 5 & 3 \\ 2 & 9 & 4 \end{array}$$

Through some calculations and trial and error method.

Is there any strategy or way of approach to this problem, or is trial and error method the solution to it? These are called "magic squares". For the case of a three-by-three magic square, there _is_ only one solution. This question might just have the lowest "views:upvotes" ratio I have ever seen (2:56585) @ghosts_in_the_code For a non-zero vote count, certainly. How the heck did this get so many views? Did it make Hot Network Questions for a year?!

• Alan Correct answer

6 years ago

There is a general, very simple, algorithm for generating any magic square which has an odd number of rows/columns as follows:

1. Start in the middle of the top row and enter 1.
2. Move Up 1 and Right 1 wrapping both vertically and horizontally when you leave the grid *(see note below).
3. If that square is empty enter the next number; if the square is not empty put the next number underneath the last number you entered.
4. Repeat 2&3 until the grid is complete. All rows, columns and the two diagonals will sum to the same value.

Here is the 5x5 square:

$$\begin{array}{ccccc} 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 \end{array}$$

As the square square is symmetric there are eight symmetries. You can also get these symmetries by a simple variation of the start square and direction used in step 2.

*Note: So as you are in the middle of the top row on the first move you want to place the next number in the next column of the row above. The row above does not exist so move to the last row of the square in the same column. If you were in the last column you would move to the first column. If you look at the example of the 5x5 at number 15. The next position is the square up and to the right of 15 which wraps on both the row and column to point to the lower right square which has 11 in it. As that square is not empty we placed 16 underneath 15. Thank you @ Alan for explaining it so well and generalising it. Does this method have a name? It helped me very much. :) @Freya No problem, unfortunately I do not know if this method has a name, my father taught me this over 35 years ago and it all came back when I saw your question :). There should be an algorithm for magic square with an even number of rows/columns somewhere. @ Alan I see. It is a very nice way and I am glad to have been taught this. :) This link me be of use for even squares; http://m.wikihow.com/Solve-a-Magic-Square (@Freya and answerer) We call this as rolling numbers. as we have to roll the paper edges when we want to move up and left

License under CC-BY-SA with attribution

Content dated before 6/26/2020 9:53 AM
• {{ error }}