So far I have been using python to generate permutations of matrices for finding magic squares. So what I have been doing so far (for 3×3 matrices) is that I find all the possible permutations of the set {1,2,3,4,5,6,7,8,9} using itertools.permutations, store them as a list and do my calculations and print my results.
Now I want to find out magic squares of order 4. Since finding all permutations means 16! possibilities, I want to increase efficiency by placing likely elements in the corner, for example 1, 16 on diagonal one corners and 4, 13 on diagonal two corners.
So how would I find permutations of set {1,2….16} where some elements are not moved is my question
1 Answer