1

The magic squares that are formed with the first 9 numbers are:
[[6, 1, 8], [7, 5, 3], [2, 9, 4]]
[[2, 7, 6], [9, 5, 1], [4, 3, 8]] etc etc (8 magic squares with permutations)

I would like to eliminate the permutations, so that it is considered a single magic square, like this: [[6, 1, 8], [7, 5, 3], [2, 9, 4]]
It is very difficult to perform operations on memory data, that is, on the results of the processing.
I would like to work on the data in memory and make comparisons on fly

`

from itertools import permutations
x=[1,2,3,4,5,6,7,8,9]
for a in permutations(x,9):
        if a[0]+a[1]+a[2]==15 and a[3]+a[4]+a[5]==15:
         if a[6]+a[7]+a[8]==15 and a[0]+a[3]+a[6]==15:
            if a[1]+a[4]+a[7]==15 and a[2]+a[5]+a[8]==15:
                if a[0]+a[4]+a[8]==15 and a[2]+a[4]+a[6]==15:
                    print(a[0:3])
                    print(a[3:6])
                    print(a[6:])
                    print()

`

`

marilu71
  • 11
  • 3

0 Answers0