《2018年刑偵科推理試題》Python版求解?(? ???ω??? ?)?
原文發表在個人博客Eajack Blog
昨天刷知乎想法,看到Milo Yip的深夜暴力編程,感覺有點意思,所有嘗試用py寫了下…思路沒什麼,就是暴力遍歷而已,純粹一時興起~先拋結果:BCACACDABA
Python代碼如下:
# !/usr/bin/env python3# -*- coding : utf-8 -*-# ==================================================================================================================# Author: Eajack# date:2018/3/7# ==================================================================================================================# Function:# 2018年刑偵科推理試題,暴力遍歷……# ==================================================================================================================# Results:# [B, C, A, C, A, C, D, A, B, A]# [Finished in 5.7s]# 經過檢驗,答案都是對的(如果沒眼花的話……)# ==================================================================================================================def preparation(answers): global maxCount,maxOption,minCount,minOption numCountsDict = {i:answers.count(i) for i in set(answers)} numCountsList = [] for key,value in numCountsDict.items(): numCountsList.append([value,key]) numCountsList = sorted(numCountsList,reverse = True) maxCount = numCountsList[0][0] maxOption = numCountsList[0][1] minCount = numCountsList[-1][0] minOption = numCountsList[-1][1]def Q3Test(answers): if(answers[2] == 1): return (answers[5]==answers[1]==answers[3] and answers[2]!=answers[5]) else: if(answers[2]==2): return (answers[2]==answers[1]==answers[3] and answers[5]!=answers[2]) else: if(answers[2]==3): return (answers[2]==answers[5]==answers[3] and answers[1]!=answers[2]) else: return (answers[2]==answers[5]==answers[1] and answers[3]!=answers[2])def Q4Test(answers): trueList = [int(answers[0]==answers[4]),int(answers[1]==answers[6]),int(answers[0]==answers[8]),int(answers[5]==answers[9])] if(sum(trueList)==1 and trueList[answers[3]-1]==1): return True else: return Falsedef Q6Test(answers): if(answers[5] == 1): return (answers[1]==answers[3]==answers[7]) else: if(answers[5]==2): return (answers[0]==answers[5]==answers[7]) else: if(answers[5]==3): return (answers[2]==answers[9]==answers[7]) else: return (answers[4]==answers[8]==answers[7])def Q8Test(answers): if(answers[7] == 1): return (abs(answers[6]-answers[0])!=1) else: if(answers[7]==2): return (abs(answers[4]-answers[0])!=1) else: if(answers[7]==3): return (abs(answers[1]-answers[0])!=1) else: return (abs(answers[9]-answers[0])!=1)if __name__ == __main__:# # globals Q2toQ5 = {1:3,2:4,3:1,4:2} Q4toQDouble = {1:[1,5],2:[2,7],3:[1,9],4:[6,10]} Q5toQX = {1:8,2:4,3:9,4:7} Q7toQY = {1:3,2:2,3:1,4:4} Q9toQZ = {1:6,2:10,3:2,4:9} Q10toQ = {1:3,2:2,3:4,4:1} answers2ADs = {1:A,2:B,3:C,4:D} maxCount = [] maxOption = [] minCount = [] minOption = []# for Q1 in range(1,5): for Q2 in range(1,5): for Q3 in range(1,5): for Q4 in range(1,5): for Q5 in range(1,5): for Q6 in range(1,5): for Q7 in range(1,5): for Q8 in range(1,5): for Q9 in range(1,5): for Q10 in range(1,5): answers = [Q1,Q2,Q3,Q4,Q5,Q6,Q7,Q8,Q9,Q10] preparation(answers) # 2題 檢驗 if(Q2toQ5[Q2] != Q5): continue; else: # 3題 檢驗 if(Q3Test(answers) != True): continue; else: # 4題 檢驗 if(Q4Test(answers) != True): continue; else: # 5題 檢驗 if(Q5 != answers[Q5toQX[Q5]-1]): continue; else: # 6題 檢驗 if(Q6Test(answers) != True): continue; else: # 7題 檢驗 if(minOption != Q7toQY[Q7]): continue; else: # 8題 檢驗 if(Q8Test(answers) != True): continue; else: # 9題 檢驗 if((Q1==Q6) == (answers[Q9toQZ[Q9]-1] == Q5)): continue; else: # 10題 檢驗 if(maxCount - minCount != Q10toQ[Q10]): continue; else: answersADs = [answers2ADs[answer] for answer in answers ] print(answersADs)
推薦閱讀:
※OpenCV零碎點筆記
※英偉達技巧教程是什麼?
※okhttp support 307 redirect for palo
※沈向洋:You Are What You Write,大家都要看
※將 view 矩陣分解成 eye、target、up