43 lines
897 B
Python

m = 0
def eq(l):
if l[0] + l[1] - l[2] - l[5]:
return False
if l[2] + l[3] - l[4] - l[7]:
return False
if l[4] + l[5] - l[6] - l[9]:
return False
if l[6] + l[7] - l[8] - l[1]:
return False
return True
def ext(l):
o = l[1::2]
e = l[::2]
while e[0] != min(e):
o = o[1:] + o[0:1]
e = e[1:] + e[0:1]
o = list(map(lambda x: str(x), o))
e = list(map(lambda x: str(x), e))
s = o[1:] + o[0:1]
return ''.join([''.join(x) for x in zip(e, o, s)])
def num(l):
bn = ext(l)
if len(bn) != 16:
return 0
return int(bn)
def mksq(sq, pl):
if not pl:
if eq(sq):
n = num(sq)
global m
if n > m:
m = n
print(m)
for it in pl:
mksq(sq + [it], list(filter(lambda x: x != it, pl)))
mksq([], list(range(1, 11)))