题目185:猜数字游戏
Number MindThe game Number Mind is a variant of the well known game Master Mind.
Instead of coloured pegs, you have to guess a secret sequence of digits. After each guess you're only told in how many places you've guessed the correct digit. So, if the sequence was 1234 and you guessed 2036, you'd be told that you have one correct digit; however, you would NOT be told that you also have another digit in the wrong place.
For instance, given the following guesses for a 5-digit secret sequence,
90342 ;2 correct
70794 ;0 correct
39458 ;2 correct
34109 ;1 correct
51545 ;2 correct
12531 ;1 correct
The correct sequence 39542 is unique.
Based on the following guesses,
5616185650518293 ;2 correct
3847439647293047 ;1 correct
5855462940810587 ;3 correct
9742855507068353 ;3 correct
4296849643607543 ;3 correct
3174248439465858 ;1 correct
4513559094146117 ;2 correct
7890971548908067 ;3 correct
8157356344118483 ;1 correct
2615250744386899 ;2 correct
8690095851526254 ;3 correct
6375711915077050 ;1 correct
6913859173121360 ;1 correct
6442889055042768 ;2 correct
2321386104303845 ;0 correct
2326509471271448 ;2 correct
5251583379644322 ;2 correct
1748270476758276 ;3 correct
4895722652190306 ;1 correct
3041631117224635 ;3 correct
1841236454324589 ;3 correct
2659862637316867 ;2 correct
Find the unique 16-digit secret sequence.
题目:
猜数字游戏 Number Mind 是著名游戏 Master Mind 的一个变种。
与着色的柱子不同,你现在必须猜测一个秘密的数的序列。每次猜测之后,你只能得知你猜中多少个正确位置。因此,如果序列是 1234,你猜是 2036,则它会告诉你,你猜对了一个数字;但是,你在错误位置上放了另一个数字时,它是不会告诉你的。
比如,给出一个 5 位的数字序列的猜测结果,
90342 ;2 位正确
70794 ;0 位正确
39458 ;2 位正确
34109 ;1 位正确
51545 ;2 位正确
12531 ;1 位正确
可以得到唯一正确的序列 39542。
基于下面的猜测结果,
5616185650518293 ;2 位正确
3847439647293047 ;1 位正确
5855462940810587 ;3 位正确
9742855507068353 ;3 位正确
4296849643607543 ;3 位正确
3174248439465858 ;1 位正确
4513559094146117 ;2 位正确
7890971548908067 ;3 位正确
8157356344118483 ;1 位正确
2615250744386899 ;2 位正确
8690095851526254 ;3 位正确
6375711915077050 ;1 位正确
6913859173121360 ;1 位正确
6442889055042768 ;2 位正确
2321386104303845 ;0 位正确
2326509471271448 ;2 位正确
5251583379644322 ;2 位正确
1748270476758276 ;3 位正确
4895722652190306 ;1 位正确
3041631117224635 ;3 位正确
1841236454324589 ;3 位正确
2659862637316867 ;2 位正确
请给出唯一正确的 16 位秘密序列。
import itertools as it
t = '''2659862637316867 ;2
1841236454324589 ;3
3041631117224635 ;3
4895722652190306 ;1
1748270476758276 ;3
5251583379644322 ;2
2326509471271448 ;2
2321386104303845 ;0
6442889055042768 ;2
6913859173121360 ;1
6375711915077050 ;1
8690095851526254 ;3
2615250744386899 ;2
8157356344118483 ;1
7890971548908067 ;3
4513559094146117 ;2
3174248439465858 ;1
4296849643607543 ;3
9742855507068353 ;3
5855462940810587 ;3
3847439647293047 ;1
5616185650518293 ;2'''
s = []
for i in t.split('\n'):
f = i.strip()
m = []
for j in f.split(';'):
j = j.strip()
m.append(j)
s.append(m)
s1 =[]
for each in s:
m = []
for i in each:
m.append(int(i))
s1.append((m,int(each)))
t = s1
s1.remove(t)
def shai_1():
weizhi1 = []
for i in s1:
m = []
for j in range(16):
if i != t:
m.append(j)
weizhi1.append(m)
return weizhi1
weizhi = shai_1()
def sheng():
S = []
for t in it.combinations(weizhi,s1):
s_t = ['x']*16
for x1 in range(s1):
s_t] = s1]
s_x = s_t[:]
S.append((s_x,t))
return S
def shai_2(S, t, c, weizhi):
if len(t)==16:
V = 1
for a in range(21):
count = 0
for each in range(16):
if S == s1:
count +=1
if count != s1:
V =0
break
if V == 1:
print(S)
return 1
for i in range(c,21):
s_t = S[:]
flag = 1
for j in weizhi:
if s_t == s1:
flag = 0
break
if flag == 1:
t1 = if k not in t]
for x in it.combinations(t1,s1):
t2 = t
s_y = s_t[:]
for y in range(s1):
s_y] = s1]
s_z = s_y[:]
t2 += x
c = i
shai_2(s_z, t2, c, weizhi)
def main():
M = sheng()
for i in M:
S,t = i,i
shai_2(S,t,1,weizhi)
main()
页:
[1]