A normal magic square, henceforth referred to as a magic square, is an arrangement of integers from 1 to n2 arranged in an n by n grid. Each number occurs only once, and the sum of the numbers in each row, column or diagonal add up to the same number.
#To Run
javac GenerateMagicSquares.java
java GenerateMagicSquares
What order [3,4] Magic Square would you like to solve? 3
Finding all magic matricies of order 3
1:
[4, 9, 2, 3, 5, 7, 8, 1, 6]
[4, 3, 8, 9, 5, 1, 2, 7, 6]
[6, 1, 8, 7, 5, 3, 2, 9, 4]
[6, 7, 2, 1, 5, 9, 8, 3, 4]
[2, 9, 4, 7, 5, 3, 6, 1, 8]
[2, 7, 6, 9, 5, 1, 4, 3, 8]
[8, 1, 6, 3, 5, 7, 4, 9, 2]
[8, 3, 4, 1, 5, 9, 6, 7, 2]
Computed Result: 8
Sum in each row & each column = 3*(3^2+1)/2 = 15