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

I'd like to populate a "tic tac toe" board (grid of 3 x 3 squares) with four appropriate entries at which time a user will attempt to solve. I'm having a hard time coming up with a mathematical solution to creating the four initial entries.

A picture is worth a thousand words so here is a picture of one particular initial setup and solution.

I'm making a web-based game for my kids that encourages them to learn the basics of algebra. The game and source code (Action Script 3) will be available on my action script note page.

I can come up with something that uses brute force to figure out solutions but I'm hoping there is an elegant mathematical solution I can utilize.

share|cite|improve this question
You want to create a magic square, right? – Pedro Tamaroff Apr 18 '12 at 18:46
up vote 1 down vote accepted

I think, as Peter comments, that you are trying to construct magic squares, that is, $3\times3$ arrays of positive integers such that all the row, column, and diagonal sums are equal. All such squares can be obtained from $$\matrix{a+(b-c)/2&a+c&a-(b+c)/2\cr a-b&a&a+b\cr a+(b+c)/2&a-c&a-(b-c)/2\cr}$$ by putting in integers for $a,b,c$. You need $a\gt|b|$, $a\gt|c|$, and $b$ and $c$ must either both be odd or both even. For example, the choice $a=5$, $b=2$, $c=-4$ will give you $$\matrix{8&1&6\cr3&5&7\cr4&9&2\cr}$$

share|cite|improve this answer
This is what I was looking for, thank you. I didn't realize this was called a "magic square". Now I'm off to program a random magic square generator puzzle in Action Script 3. I appreciate the help! – ptay Apr 21 '12 at 0:45
Glad to be of service. The standard way to thank someone here is to "accept" the answer, by ticking the check mark next to the answer. – Gerry Myerson Apr 21 '12 at 1:37
Will do, thanks! – ptay Apr 28 '12 at 17:32

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.