Tag Info

Hot answers tagged

2

magicSquare2[n_] /; Mod[n, 4] == 0 := Module[{mat, square, bools}, mat = ConstantArray[Range[1., n], n]; square = Partition[Range[n^2], n]; bools = UnitStep@-Abs[# - #\[Transpose] &@Floor[Mod[mat, 4]/2]]; n^2 + 1 - #1 &@square bools + (1 - bools) square] ans1 = magicSquare[3000]; // AbsoluteTiming ans2 = magicSquare2[3000]; // AbsoluteTiming ...



Only top voted, non community-wiki answers of a minimum length are eligible