Semimagic Square

Author

Eric W. Weisstein
March 1, 2009

This notebook downloaded from http://mathworld.wolfram.com/notebooks/RecreationalMath/SemimagicSquare.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/SemimagicSquare.html.

©2009 Wolfram Research, Inc. except for portions noted otherwise

Usage

?SemimagicQ

?MagicQ

Counts

2×2

With[{n=2},Select[Union[CanonicalizeArray/@(Partition[#,n]&/@Permutations[Range[n^2]])],SemimagicQ]
]

3×3

With[{n=3},sm3=Select[Union[CanonicalizeArray/@(Partition[#,n]&/@Permutations[Range[n^2]])],SemimagicQ[#]&&!MagicQ[#]&]
]//Length//Timing

GraphicsGrid[Partition[MagicSquarePlot/@sm3,4,4,{1,1},{}],ImageSize->400]

And@@SemimagicQ/@sm3

MagicQ/@sm3

4×4

ByteCount[Partition[Range[4^2],4]]

16! 124/10^9.

With[{n=4},sm4=Select[Union[CanonicalizeArray/@(Partition[#,n]&/@Permutations[Range[n^2]])],SemimagicQ]
]//Length//Timing