设万维读者为首页 广告服务 技术服务 联系我们 关于万维
简体 繁体 手机版
分类广告
版主:诤友
万维读者网 > 教育学术 > 跟帖
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 | 全球最佳航空公司出炉:海航获五星
海外华人福利!在线看陈建斌《三叉戟》热血归回 豪情筑梦 高清免费看 无地区限制