I have a few question regarding magic squares. According to wikipedia a magic square is defined as an n x n matrix where the rows in each direction (horizontal, vertical, diagonal) sum up to the same number, the magic constant.

When generating such a magic square what conditions need to be met?

  1. Can I generate a magic sqaure for any number in a 4x4 square where the magic constant d is > 4? If not, how to I figure out what's the smallest number I can generate a magic square for a sqaure of a certain size?

  2. How many combinations do exist for a magic constant d in an n x n square?

  3. What's the most efficent algorithm to find all magic squares for for a given magic constant and a given square width?

  4. Are their certain numbers for which you can not generate a magic square (except those where d < n)

I hope someone can clarify this for me a bit.

  • $\begingroup$ Welcome to MSE. Please use MathJax. $\endgroup$ – José Carlos Santos Oct 1 '17 at 12:47
  • $\begingroup$ you missed at least one part of the definition of a magic square. $\endgroup$ – user451844 Oct 1 '17 at 13:11
  • $\begingroup$ Do you want only standard magic squares or also arbitary magic squares ? $\endgroup$ – Peter Oct 1 '17 at 13:28
  • $\begingroup$ @Peter magic squares which only result in d in the horizontal, vertical and diagonal. $\endgroup$ – yq8 Oct 1 '17 at 13:44

For Question 1

From the source, Magic Square, it says that 'A magic square is a n*n square grid (where n is the number of cells on each side) filled with distinct positive integers, which means that the numbers in the cells cannot have decimals, which means that you can't have the magic number as four for 4x4 square. Though you can probably create a magic square with decimals if you want.

For Question 2 and 3

Here is a useful document:

Magic Squares

For Question 4

No. Source: Magic Squares

Hope this helps!

  • $\begingroup$ Could you please update the links above? They do not work. $\endgroup$ – Nick Feb 26 at 0:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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