Python版锯齿状代码实现 2018年刑侦科推理题
```python# -*- coding: utf-8 -*-# @Time: 2020/7/15 12:45# @Author: lagelanren# @Email: forhaogege@163.com# @File: what_is_elegance.py# @Software: PyCharmdef main():answer = [0]*10answer_letter = []whi
·
```python
# -*- coding: utf-8 -*-
# @Time : 2020/7/15 12:45
# @Author : lagelanren
# @Email : forhaogege@163.com
# @File : what_is_elegance.py
# @Software: PyCharm
def main():
answer = [0]*10
answer_letter = []
while(answer[-1]!=4):
#开始构造答案
a = b = c = d = 0
for k,i in enumerate(answer):
if i == 4:
answer[k] = 0
answer[k+1] += 1
break
else:
answer[0] += 1
if 4 not in answer:
#答案丢进去试
for i in answer:
if i == 0:
a += 1
if i == 1:
b += 1
if i == 2:
c += 1
if i == 3:
d += 1
for k,less in enumerate([a,b,c,d]):
if less == min(a,b,c,d):
if k == 0:
less = 0
if k == 1:
less = 1
if k == 2:
less = 2
if k == 3:
less = 3
break
if (answer[1] == 0 and answer[4] == 2) or (answer[1] == 1 and answer[4] == 3) or (answer[1] == 2 and answer[4] == 0) or (answer[1] == 3 and answer[4] == 1):
if answer[2] == 0 or answer[2] == 1 or answer[2] == 3:
if (answer[3] == 0 and answer[0] == answer[4]) or (answer[3] == 1 and answer[1] == answer[6]) or (answer[3] == 2 and answer[0] == answer[8]) or (answer[3] == 3 and answer[5] == answer[9]):
if (answer[4] == 0 and answer[7] == 0) or (answer[4] == 1 and answer[3] == 1) or (answer[4] == 2 and answer[8] == 2) or (answer[4] == 3 and answer[6] == 3):
if (answer[5] == 0 and answer[7] == answer[1] == answer[3]) or (answer[5] == 1 and answer[7] == answer[0] == answer[5]) or (answer[5] == 2 and answer[7] == answer[2] == answer[9]) or (answer[5] == 3 and answer[7] == answer[4] == answer[8]):
if (answer[6] == 0 and less == 2) or (answer[6] == 1 and less == 1) or (answer[6] == 2 and less == 0) or (answer[6] == 3 and less == 3):
if (answer[7] == 0 and (answer[0]-answer[6] not in [1,-1])) or (answer[7] == 1 and (answer[0]-answer[5] not in [1,-1])) or (answer[7] == 2 and (answer[0]-answer[1] not in [1,-1])) or (answer[7] == 3 and (answer[0]-answer[9] not in [1,-1])):
if answer[0] == answer[5]:
if (answer[8] == 0 and (answer[5] != answer[4])) or (answer[8] == 1 and (answer[9] != answer[4])) or (answer[8] == 2 and (answer[1] != answer[4])) or (answer[8] == 3 and (answer[8] != answer[4])):
if (answer[9] == 0 and (max(a,b,c,d) - min(a,b,c,d)) == 3) or (answer[9] == 1 and (max(a,b,c,d) - min(a,b,c,d)) == 2) or (answer[9] == 2 and (max(a,b,c,d) - min(a,b,c,d)) == 4) or (answer[9] == 3 and (max(a,b,c,d) - min(a,b,c,d)) == 1):
break
if answer[0] != answer[5]:
if (answer[8] == 0 and (answer[5] == answer[4])) or (answer[8] == 1 and (answer[9] == answer[4])) or (answer[8] == 2 and (answer[1] == answer[4])) or (answer[8] == 3 and (answer[8] == answer[4])):
if (answer[9] == 0 and (max(a,b,c,d) - min(a,b,c,d)) == 3) or (answer[9] == 1 and (max(a,b,c,d) - min(a,b,c,d)) == 2) or (answer[9] == 2 and (max(a,b,c,d) - min(a,b,c,d)) == 4) or (answer[9] == 3 and (max(a,b,c,d) - min(a,b,c,d)) == 1):
break
#答案成ABCD
for k, i in enumerate(answer):
k = str(k + 1)
if i == 0:
answer_letter.append(k + "A ")
if i == 1:
answer_letter.append(k + "B ")
if i == 2:
answer_letter.append(k + "C ")
if i == 3:
answer_letter.append(k + "D ")
print(answer_letter)
if __name__ == '__main__':
main()
更多推荐
已为社区贡献1条内容
所有评论(0)