Math Is Fun Forum
  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2011-08-05 07:45:25

namealreadychosen
Member
Registered: 2011-07-23
Posts: 16

using Python to search for magic squares of squares

In any magic square of squares, either all the entries are 1(mod3) or all the entries are 0(mod3) because any square is ==0 or 1(mod3) and the sum of each row, column and diagonal, here denoted C, is 3 times the middle entry, therefore C==0(mod3) and only 0,0,0 and 1,1,1 sum to 0(mod3) out of the possible combinations of 0s and 1s. If all the entries are ==0(mod3), they must also be ==0(mod9) because they are square and if each entry is divided by 9 a new magic square of squares will be created. Hence, if there exist any magic squares of squares, there exist some with all entries ==1(mod3) which is ==1 or 4 or 7(mod9).

The only possible combinations summing to 3(mod9) are 1,4,7 and 1,1,1 and 7,7,7 and 4,4,4.
If all entries are the same modulo 9, either they are all identical, which give an infinite number of solutions, or they are different modulo some other power of 3.

Python code to check the C==3(mod9) case

x=[7,4,1]
y=[1,7,4]
z=[7,1,4]
w=[1,4,7]
t=[4,7,1]
u=[4,1,7]
q=[x,y,z,w,t,u]
for a in q:
    for b in q:
        for c in q:
            h=2
            for n in range(3):
                l=[a[n],b[n],c[n]]
                if l not in q:
                    h=3
            if [a[0],b[1],c[2]] not in l or [a[2],b[1],c[0]] not in l:
                h=3
            if h==2:
                print(a,b,c)
print("done")

The only possible combinations summing to 6(mod9) are 1,1,4 and 7,7,1.

Python code to check the C==6(mod9) case

x=[1,1,4]
y=[1,4,1]
z=[4,1,1]
w=[7,7,1]
t=[7,1,7]
u=[1,7,7]
q=[t,u,w,x,y,z]
for a in q:
    for b in q:
        for c in q:
            h=2
            for n in range(3):
                l=[a[n],b[n],c[n]]
                if l not in q:
                    h=3
            if [a[0],b[1],c[2]] not in l or [a[2],b[1],c[0]] not in l:
                h=3
            if h==2:
                print(a,b,c)
print("done")

The only possible combination summing to 0(mod9) are 1,1,7 and 7,7,4 and 4,4,1.

Python code to check the C==0(mod9) case

x=[1,1,7]
y=[7,7,4]
z=[7,1,1]
w=[1,7,1]
t=[4,4,1]
u=[7,4,7]
v=[4,7,7]
r=[4,1,4]
s=[1,4,4]
q=[r,s,t,u,v,w,x,y,z]
for a in q:
    for b in q:
        for c in q:
            h=2
            for n in range(3):
                l=[a[n],b[n],c[n]]
                if l not in q:
                    h=3
            if [a[0],b[1],c[2]] not in l or [a[2],b[1],c[0]] not in l:
                h=3
            if h==2:
                print(a,b,c)
print("done")

My laptop checked through all possible values for the entries (mod9) and I conclude that all magic squares of squares have all entries the same (modulo 9) unless me or the laptop made an error.

Last edited by namealreadychosen (2011-08-05 22:06:32)

Offline

Board footer

Powered by FluxBB