1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| import itertools
initstate=[3,3,0,2,2,2,2,1,2]
update=[
[1,2,4,5],
[1,2,3],
[2,3,5,6],
[1,4,7],
[2,4,5,6,8],
[3,6,9],
[4,5,7,8],
[7,8,9],
[5,6,8,9]
]
for i in itertools.product([0,1,2,3],repeat=9):
initstate=[3,3,0,2,2,2,2,1,2]
for j in range(9):
for k in update[j]:
initstate[k-1]+=i[j]
initstate[k-1]%=4
if sum(initstate)==0:
print ' '.join([' '.join(str(m+1)*i[m]) for m in range(9) if i[m]!=0])
break
# 4 5 8 9
|