Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
2018年刑侦科目推理试题
# http://news.sina.com.cn/s/wh/2018-03-02/doc-ifyrztfz6281140.shtml
def main():
ans = [None for _ in range(10+1)]
def least_answered(ans):
vs = ans[1:]
vc = {v:vs.count(v) for v in vs}
minc = min(vc.values())
for v,c in vc.items():
if c == minc:
return v
raise Exception('error')
def q10(ans):
vs = ans[1:]
vc = [vs.count(v) for v in vs]
minc = min(vc)
maxc = max(vc)
return maxc - minc
check = {
(1, 'a'): (1, lambda: True),
(1, 'b'): (1, lambda: True),
(1, 'c'): (1, lambda: True),
(1, 'd'): (1, lambda: True),
(2, 'a'): (5, lambda: ans[5] == 'c'),
(2, 'b'): (5, lambda: ans[5] == 'd'),
(2, 'c'): (5, lambda: ans[5] == 'a'),
(2, 'd'): (5, lambda: ans[5] == 'b'),
(3, 'a'): (6, lambda: ans[6] == ans[2] and ans[6] == ans[4] and ans[6] != ans[3]),
(3, 'b'): (6, lambda: ans[3] == ans[2] and ans[3] == ans[4] and ans[3] != ans[6]),
(3, 'c'): (6, lambda: ans[3] == ans[6] and ans[3] == ans[4] and ans[3] != ans[2]),
(3, 'd'): (6, lambda: ans[3] == ans[6] and ans[3] == ans[2] and ans[3] != ans[4]),
(4, 'a'): (5, lambda: ans[1] == ans[5]),
(4, 'b'): (7, lambda: ans[2] == ans[7]),
(4, 'c'): (9, lambda: ans[1] == ans[9]),
(4, 'd'): (10, lambda: ans[6] == ans[10]),
(5, 'a'): (8, lambda: ans[5] == ans[8]),
(5, 'b'): (5, lambda: ans[5] == ans[4]),
(5, 'c'): (9, lambda: ans[5] == ans[9]),
(5, 'd'): (7, lambda: ans[5] == ans[7]),
(6, 'a'): (8, lambda: ans[8] == ans[2] and ans[8] == ans[4]),
(6, 'b'): (8, lambda: ans[8] == ans[1] and ans[8] == ans[6]),
(6, 'c'): (10, lambda: ans[8] == ans[3] and ans[8] == ans[10]),
(6, 'd'): (9, lambda: ans[8] == ans[5] and ans[8] == ans[9]),
(7, 'a'): (10, lambda: least_answered(ans) == 'c'),
(7, 'b'): (10, lambda: least_answered(ans) == 'b'),
(7, 'c'): (10, lambda: least_answered(ans) == 'a'),
(7, 'd'): (10, lambda: least_answered(ans) == 'd'),
(8, 'a'): (7, lambda: abs(ord(ans[1]) - ord(ans[7])) > 1),
(8, 'b'): (5, lambda: abs(ord(ans[1]) - ord(ans[5])) > 1),
(8, 'c'): (2, lambda: abs(ord(ans[1]) - ord(ans[2])) > 1),
(8, 'd'): (10, lambda: abs(ord(ans[1]) - ord(ans[10])) > 1),
(9, 'a'): (6, lambda: (ans[1] == ans[6]) != (ans[6] == ans[5])),
(9, 'b'): (10, lambda: (ans[1] == ans[6]) != (ans[10] == ans[5])),
(9, 'c'): (5, lambda: (ans[1] == ans[6]) != (ans[2] == ans[5])),
(9, 'd'): (9, lambda: (ans[1] == ans[6]) != (ans[9] == ans[5])),
(10, 'a'): (10, lambda: q10(ans) == 3),
(10, 'b'): (10, lambda: q10(ans) == 2),
(10, 'c'): (10, lambda: q10(ans) == 4),
(10, 'd'): (10, lambda: q10(ans) == 1)
}
to_check = [None for _ in range(10+1)]
i = 1
ca = 'a'
ans[0] = '0'
while i > 0:
if i == 11:
print([x for x in ans[1:]])
i -= 1
ca = chr(ord(ans[i]) + 1)
continue
if ca == 'e':
i -= 1
ca = chr(ord(ans[i]) + 1)
continue
assert ord('a') <= ord(ca) <= ord('d')
ans[i] = ca
to_check[i] = check[(i, ans[i])]
if all(min_i > i or check_fn() for min_i, check_fn in to_check[1:i+1]):
i += 1
ca = 'a'
else:
ca = chr(ord(ans[i]) + 1)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.