• + 5 comments

    With Python, a brute force way to generate all magic squares is to generate all possible permutations of 1 to 9 with itertools.permutations then check each created list to see if the sums of all rows, columns and diagonals are equal. I added the sums to a set then checked if the length of the set was 1 to determine if it was a magic square.