TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Einstein's election riddle: are you in the two per cent that can solve it?

3 点作者 samaysharma大约 10 年前

1 comment

todd8大约 10 年前
I came up with the following approach in Python last time I saw this puzzle here (see: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=7734998" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=7734998</a>)<p><pre><code> from itertools import permutations as perms houses = range(5) # numbered 0, 1, 2, 3, 4 for david, ed, nick, nicola, nigel in perms(houses): if nick != 0: continue # by 9. for tartan, paisley, gingham, striped, polka_dot in perms(houses): if nicola != tartan: continue # by 1. if paisley != gingham - 1: continue # by 4. if nick not in [polka_dot-1, polka_dot+1]: continue # by 14. for mochaccino, flat_white, dbl_espresso, chai, decaf in perms(houses): if dbl_espresso != 2: continue # by 8. if david != mochaccino: continue # by 3. if paisley != flat_white: continue # by 5. for car, bike, train, foot, plane in perms(houses): if striped != bike: continue # by 7. if plane != chai: continue # by 12. if nigel != foot: continue # by 13. if train not in [decaf-1, decaf+1]: continue for guinea_pig, squirrel, pitbull, badger, fish in perms(houses): if ed != guinea_pig: continue # by 2. if car != squirrel: continue # by 6. if badger not in [bike-1, bike+1]: continue # by 11. if train not in [pitbull-1, pitbull+1]: continue # by 10. person = {david: &quot;David&quot;, ed: &quot;Ed&quot;, nick: &quot;Nick&quot;, nicola: &quot;Nicola&quot;, nigel: &quot;Nigel&quot;} print &quot;{} owns the fish&quot;.format(person[fish]) </code></pre> Running this reveals that there is one solution, Nigel owns the fish.