設萬維讀者為首頁 廣告服務 技術服務 聯繫我們 關於萬維
簡體 繁體 手機版
分類廣告
版主:諍友
萬維讀者網 > 教育學術 > 跟帖
python code
送交者: xi11west 2017月04月03日11:58:23 於 [教育學術] 發送悄悄話
回  答: Benren2:小學一年級算術題蠻力破解程序Benren2 於 2017-04-01 22:27:04

>>> import itertools
>>> for a,b,c,d,e,f,g,h in itertools.permutations(range(1,9), 8):
...     if a+b==9 and c+d==7 and e-f==1 and g-h==3: break
...
>>> (a,b,c,d,e,f,g,h)
(1, 8, 3, 4, 7, 6, 5, 2)

total 8! = 40320 possibilities, the speed difference should not be noticeable if properly programmed. 

0%(0)
0%(0)
標  題 (必選項):
內  容 (選填項):
實用資訊
回國機票$360起 | 商務艙省$200 | 全球最佳航空公司出爐:海航獲五星
海外華人福利!在線看陳建斌《三叉戟》熱血歸回 豪情築夢 高清免費看 無地區限制