S先生与P先生谜题,谜题,[Python]代码de
S先生与P先生谜题,谜题,[Python]代码de
[Python]代码
def gatherBy(seq, f): d = {} for x in seq: d.setdefault(f(x), []).append(x) return dpool = [(a, b) for a in range(2, 98 + 1) for b in range(2, a + 1)]Sums = gatherBy(pool, lambda x: x[0] + x[1])Prods = gatherBy(pool, lambda x: x[0] * x[1])def MrP_dont_know(p): return len(Prods[p]) != 1def MrS_dont_know(s): return len(Sums[s]) != 1def MrS_know_MrP_doesnt_know(s): return all([MrP_dont_know(a * b) for a, b in Sums[s]])def MrP_now_knows(p): return len([(a, b) for a, b in Prods[p] if MrS_know_MrP_doesnt_know(a + b)]) == 1def MrS_knows_MrP_now_know(s): return len([(a, b) for a, b in Sums[s] if MrP_now_knows(a * b)]) == 1for a, b in pool: s = a + b p = a * b if MrP_dont_know(p) and MrS_dont_know(s) and MrS_know_MrP_doesnt_know(s)\ and MrP_now_knows(p) and MrS_knows_MrP_now_know(s): print a, b#result : 13 4
相关内容
- 对mysqldb的一个简单封装,mysqldb简单封装,对于python-my
- 多线程,限制线程数运行,,多线程限制线程数,[Python]代
- 使用PyQt4的QtWebKit对整个网页截图,pyqt4qtwebkit截图,pag
- 登录网站,,Copy来的,看起来有用
- 主要城市及时气温,主要城市气温,temperature.
- 提取网页正文,提取正文,[Python]代码#e
- python与计算物理:实现数值积分的Simpson方法,pythonsi
- 使用python的正则表达式做词法分析器,python词法,[Pyth
- 我在做FTP爆破破解 遇到点问题想请教下大师们,ftp爆
- 多线程采集图片,多线程采集,do.py#! /usr
评论关闭