from
itertools
import
combinations
from
itertools
import
product
from
itertools
import
permutations
from
itertools
import
combinations_with_replacement
import
hashlib
numbers
=
[]
dict
=
{}
anti
=
{}
def
genNums():
items
=
[
'0'
,
'1'
,
'2'
]
for
p
in
product(items, items, items, items):
if
'
'.join(p) == '
0000
' or '
'.join(p) == '
1111
' or '
'.join(p) == '
2222
':
continue
k
=
''.join(p)
numbers.append(k)
arr
=
[]
for
i
in
range
(
4
):
if
p[i]
=
=
'0'
:
arr.append(
0
)
elif
p[i]
=
=
'1'
:
arr.append(
1
)
elif
p[i]
=
=
'2'
:
arr.append(
-
1
)
else
:
print
(
'unknown num'
+
p[i])
dict
[k]
=
arr
print
(
dict
)
def
sumItem(a, b):
if
a[
0
]
+
b[
0
]
=
=
0
and
a[
1
]
+
b[
1
]
=
=
0
and
a[
2
]
+
b[
2
]
=
=
0
and
a[
3
]
+
b[
3
]
=
=
0
:
return
0
def
checkItem(items):
for
n
in
range
(
4
):
count
=
0
for
i
in
items:
if
dict
[i][n]
=
=
0
:
count
+
=
1
if
count !
=
13
:
raise
Exception(
"invalid zero"
)
for
item
in
combinations(items,
2
):
sumItem(
dict
[item[
0
]],
dict
[item[
1
]])
def
printItems(items):
str
=
''
for
i
in
range
(
4
):
for
item
in
items:
str
+
=
item[i]
return
str
def
permuteUnique(nums):
return
list
(
set
(permutations(nums)))
def
genNum2():
data
=
list
(
'0'
*
13
+
'1'
*
13
+
'2'
*
13
)
all
=
permuteUnique(data)
print
(
len
(
all
))
for
i
in
all
:
print
(''.join(i))
def
getInfo(l):
info
=
[
0
,
0
,
0
]
for
i
in
l:
if
dict
[i][
1
]
=
=
0
:
info[
0
]
+
=
1
elif
dict
[i][
1
]
=
=
1
:
info[
1
]
+
=
1
elif
dict
[i][
1
]
=
=
-
1
:
info[
2
]
+
=
1
return
info
def
brute2():
genNums()
array0
=
[]
array12
=
[]
array1
=
[]
array2
=
[]
tmp1
=
[]
tmp2
=
[]
dict01
=
{}
dict02
=
{}
for
i
in
combinations(numbers,
2
):
if
sumItem(
dict
[i[
0
]],
dict
[i[
1
]])
=
=
0
:
anti[i[
0
]]
=
i[
1
]
anti[i[
1
]]
=
i[
0
]
if
i[
0
][
0
]
=
=
'0'
:
array0.append(
list
(i))
elif
i[
0
][
0
]
=
=
'1'
:
array1.append(
list
(i)[
0
])
set1
=
set
(array1)
else
:
print
(i)
if
i[
0
][
0
]
=
=
'0'
:
if
not
i[
0
]
in
dict01.keys():
dict01[i[
0
]]
=
[]
if
not
i[
0
]
in
dict02.keys():
dict02[i[
0
]]
=
[]
if
i[
1
][
0
]
=
=
'1'
:
dict01[i[
0
]].append(i[
1
])
elif
i[
1
][
0
]
=
=
'2'
:
dict02[i[
0
]].append(i[
1
])
for
i0
in
product(array0[
0
], array0[
1
], array0[
2
], array0[
3
], array0[
4
], array0[
5
], array0[
6
], array0[
7
], array0[
8
], array0[
9
], array0[
10
], array0[
11
], array0[
12
]):
l
=
list
(i0)
l.sort()
set1
=
set
()
for
i
in
l:
if
len
(set1)
=
=
0
:
set1
=
set
(dict01[i])
else
:
set1
=
set1 &
set
(dict01[i])
print
(l, set1)
l1
=
list
(set1)
l1.sort()
for
i1
in
combinations(l1,
13
):
tmp
=
list
(set1
-
set
(i1))
tmp.sort()
l2
=
[]
for
i2
in
tmp:
l2.append(anti[i2])
l2.sort()
l1
=
list
(i1)
l1.sort()
info
=
getInfo(l)
info1
=
getInfo(l1)
info2
=
getInfo(l2)
if
info[
0
]
+
info1[
0
]
+
info2[
0
]
=
=
13
and
info[
1
]
+
info1[
1
]
+
info2[
1
]
=
=
13
and
info[
2
]
+
info1[
2
]
+
info2[
2
]
=
=
13
:
str
=
printItems(l
+
l1
+
l2)
if
hashlib.md5(
str
.encode()).hexdigest()
=
=
"aac82b7ad77ab00dcef90ac079c9490d"
:
print
(
str
)
if
__name__
=
=
'__main__'
:
brute2()