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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

100 prisoners problem

324 点作者 bladecatcher大约 7 年前

17 条评论

micaeked大约 7 年前
Since wikipedia doesn&#x27;t explain why it works (or maybe I just didn&#x27;t understand it), I found this explanation much better: <a href="http:&#x2F;&#x2F;datagenetics.com&#x2F;blog&#x2F;december42014&#x2F;index.html" rel="nofollow">http:&#x2F;&#x2F;datagenetics.com&#x2F;blog&#x2F;december42014&#x2F;index.html</a>
评论 #16990101 未加载
评论 #16987997 未加载
评论 #16988153 未加载
评论 #16988074 未加载
评论 #16991027 未加载
billysielu大约 7 年前
Right, so picking a box at random and following the chain would be bad because you could get back to where you started having not found your number. Starting with your own numbered box is your defense against this because to go back to where you started you would have to have found your number.
评论 #16990795 未加载
评论 #16991645 未加载
dbatten大约 7 年前
I&#x27;m confused...<p>&quot;Before the first prisoner enters the room, the prisoners may discuss strategy—but may not communicate once the first prisoner enters to look in the drawers.&quot;<p>And, in the example given, &quot;That prisoners 5 to 8 will also find their numbers can also be derived from the information gained by the first three prisoners.&quot;<p>There&#x27;s never any explanation of what happens when a prisoner opens a drawer and finds it empty. In the first example given, what happens when prisoner 5 goes in and there&#x27;s nothing in drawer 5? The algorithm doesn&#x27;t seem to account for this.<p>It seems like there&#x27;s some sort of assumption that the later prisoners are gathering information from the earlier prisoners, but the problem set-up seems to preclude this? They&#x27;re going into a room so they can&#x27;t watch each other, the drawers are closed afterwards so they can&#x27;t derive information from which drawers are open&#x2F;closed, and they&#x27;re not allowed to communicate.<p>Am I not following something?
评论 #16988027 未加载
评论 #16988020 未加载
评论 #16988013 未加载
评论 #16987924 未加载
评论 #16988029 未加载
评论 #16988030 未加载
评论 #16987883 未加载
edanm大约 7 年前
My favorite version of this is the one that shows one prisoner to make a single swap of two drawers&#x27; contents in order to improve their chances. Surprisingly, this allows for a 100% success rate.
评论 #16988470 未加载
评论 #16989148 未加载
评论 #16989631 未加载
评论 #16992242 未加载
martininmelb大约 7 年前
What does the prisoner do if she gets to, for example, box 40 and there is a 40 in the box?<p>[edit] I reread the explanation and get it now. Only 1 prisoner (40) will actually get to open box 40. I was trying to think of this from the point of view of implementing it in code. I guess the cycle stops when a prisoner finds their own number or reaches 50 attempts.
评论 #16989388 未加载
contoraria大约 7 年前
I still doubt the Monty Hall problem (mentioned in the wiki-article). I understand the reasoning, summing the probability tree, but there are two ways to build the probability tree, with the step of reveal or without. Since the player doesn&#x27;t know that step, why would it be part of the tree? Because we know the setup a priori, in a way.<p>I&#x27;m assuming the bigger tree is still incomplete. More levels can be inserted, reflecting the reasoning of the a priori knowledge. I assume the supposed advantage would thus prove to be imaginary. Or in simpler terms:<p>Normally the tree would have the sequence in the following order: box distribution, choose a box, reveal one empty box, switch choice or don&#x27;t.<p>However, if you are predetermined to switch, then the order would be changed to switch before the reveal. Thereby, the reveal is irrelevant to the result of switching and the probabilities are equal again.
评论 #17037052 未加载
评论 #16993754 未加载
评论 #17001429 未加载
评论 #16993680 未加载
评论 #16996411 未加载
mkstowegnv大约 7 年前
At some intuitive level this problem reminded me of other very different puzzles like [1] and prompted me to wonder if as a general rule the best tactic when one is faced by a riddle that appears impossible, is to try to think of solutions that involve self reference. It also makes me wonder if the brain at a basal unconscious level uses something analogous to the linked list like solution described here to quickly explore permutation space.<p>1 <a href="https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Knights_and_Knaves" rel="nofollow">https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Knights_and_Knaves</a>
niftich大约 7 年前
If I understand this correctly, this basically uses the drawer&#x27;s perceived number as an out-of-band signalling mechanism for the algorithm they agreed to follow. Each actor must adhere to the same scheme to address drawers. This means that the drawers must either be uniquely named (&quot;labelled&quot; ahead of time), or have some sort of natural ordering that&#x27;s algorithmically deterministic (e.g. lexicographic, array index, 2D-position using a previously agreed algorithm like right-then-down).<p>What are some practical uses for this? Distributed hash table traversal using one&#x27;s own address [1]?<p>[1] <a href="http:&#x2F;&#x2F;www.bittorrent.org&#x2F;beps&#x2F;bep_0005.html" rel="nofollow">http:&#x2F;&#x2F;www.bittorrent.org&#x2F;beps&#x2F;bep_0005.html</a>
评论 #16988014 未加载
评论 #16988009 未加载
评论 #16990979 未加载
Myrmornis大约 7 年前
Many mathematical-minded people look at this problem and conclude that the maximum probability of freedom is close to (1&#x2F;2)^50.<p>But that&#x27;s absurdly wrong. They&#x27;re out by a factor of 10^14 !!! So, are there any important problems in computer science &#x2F; software engineering contexts that have this form? If so, they may have speed-ups of several orders of magnitude that mathematically and algorithmically-minded people might completely miss?
CydeWeys大约 7 年前
I wrote up a Python framework to play around with a different 100 prisoners problem here: <a href="https:&#x2F;&#x2F;github.com&#x2F;CydeWeys&#x2F;hundred_prisoners&#x2F;tree&#x2F;master&#x2F;prisoners" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;CydeWeys&#x2F;hundred_prisoners&#x2F;tree&#x2F;master&#x2F;pr...</a><p>People might find it interesting to play around with implementing the solution in code.
engnr567大约 7 年前
One key thing about the result is that it doesn&#x27;t mean that the probability of survival is 30%. The prison director can choose an arrangement such that the strategy is guaranteed to fail. If the prison director is intelligent and after your life, you are infinitely more likely to survive by opening boxes randomly.
评论 #16992075 未加载
评论 #16992372 未加载
pramodzion大约 7 年前
HN post from 2010 : <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=1891212" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=1891212</a>
travismay1大约 7 年前
Well, this led me on a bit of a rabbit trail. I made a python script that illustrates the solution to this problem in action. <a href="https:&#x2F;&#x2F;gist.github.com&#x2F;travismay1&#x2F;8d80fe345786b1d0e93fee8127df53b5" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;travismay1&#x2F;8d80fe345786b1d0e93fee812...</a>
twentythree大约 7 年前
The third variant of the problem (where one prisoner is allowed to make one change, which can guarantee that every prisoner survives) is the one I heard first; I like that problem because it seems even more counter-intuitive, but also makes it easier to understand why it works.
jwilk大约 7 年前
Let&#x27;s make the game harder by not letting the prisoners see what&#x27;s inside the opened drawers.<p>Is it hopeless now?
评论 #16988537 未加载
评论 #16988527 未加载
keketi大约 7 年前
Do the prisoners remove their number from the drawer if they find it? It&#x27;s not clear from the problem statement.
评论 #16988661 未加载
评论 #16988057 未加载
utopcell大约 7 年前
Say you have 10 players in a row. You number each player by its position in the row: 1, 2, 3, .., 10. You then write the players&#x27; names on 10 pieces of paper, and you randomly place the papers in 10 boxes. You place exactly one paper in each of the boxes. The boxes are also numbered from 1 to 10.<p>You allow each player to look into half of the boxes. Each player can choose which boxes to look into. The player &quot;wins&quot; if they find a paper with their number written on it. But they can&#x27;t tell anyone if they won or lost, what they saw in the boxes, or which boxes they picked.<p>The problem then, is the following: Which boxes should each player look into, such that the chance of all of them &quot;winning&quot; at the same time is as high as possible.<p>For example, one way to put the 10 numbers in the 10 boxes is:<p>Box 1: 10<p>Box 2: 9<p>Box 3: 8<p>Box 4: 4<p>Box 5: 6<p>Box 6: 5<p>Box 7: 7<p>Box 8: 3<p>Box 9: 2<p>Box 10: 1<p>The ordering of the numbers in the boxes is a permutation of the 10 numbers. We know that there are 10! possible ways to place the numbers in the boxes.<p>Now, consider the following strategy that player X can use to open his 5 boxes. He first opens the box numbered X. If he sees his number in it, then he wins. Otherwise, he saw a different number Y. He then opens the box numbered Y. If he finds his number, he wins. Otherwise, he continues until he has opened the 5 boxes he is allowed to open.<p>If the player was allowed to open as many boxes as he likes, they he would always win. That is because he would either find his number in a box, or continue opening boxes he hasn&#x27;t opened before. Why is this true ? Well, let&#x27;s say it isn&#x27;t, and that he opens boxes 3 -&gt; 2 -&gt; 5 -&gt; 7 -&gt; 5. But that cannot happen: The first time he opened box 5 was because he saw the number 5 in box 2. And if he had to see box 5 again, this means that box 7 also had the number 5 in it. In fact, the only way player X could go back to a box he has seen, is when he finds his number (X) that will lead him back to the first box he opened.<p>Now, we know that a player &quot;wins&quot; if he finds his number before opening more than 5 boxes. Or, put it differently, if the loop he follows has length at most 5. In the example above, player 2 would open box 2, which would lead him to box 9, which contains number 2, forming a loop of length 2.<p>So, when do all players &quot;win&quot; at the same time ? When there does not exist a loop that has length 6 or more. Or more specifically, there is no loop of length 6, or 7, or 8, or 9, or 10. So: P_win = 1 - P_loop(6) - P_loop(7) - P_loop(8) - P_loop(9) - P_loop(10).<p>We can show [1] that P_loop(k) = 1&#x2F;k, when k &gt; 5. We need the loop to be larger than 5 because in this case, there can only be one such loop on the permutation.<p>But then P_win would be 1 - 1&#x2F;6 - 1&#x2F;7 - 1&#x2F;8 - 1&#x2F;9 - 1&#x2F;10 or ~35.4%. In general, if we have N players and N boxes then P_win would be: P_win = 1 - Sum[k=n&#x2F;2+1 .. n]P_loop(k) or P_win = 1 - ( Sum[k=1 .. N]P_loop(k) - Sum[k=1 .. N&#x2F;2]P_loop(k) ) or P_win ~= 1 - ( ln(N) - ln(N&#x2F;2) ) &gt; ~30%<p>(each sum is a harmonic series sum.)<p>[1] Why is P_loop(k) = 1&#x2F;k when k &gt; N&#x2F;2 though ?<p>Let&#x27;s say you have numbers 1, 2, .., k. All permutations of them are k!. How many of those k! permutations form a loop ? Well, at the first position, you can place any number other than &#x27;1&#x27;, so you have (k-1) choices. Say you placed number Z at position 1. Then at position Z, you can&#x27;t place &#x27;1&#x27; and you can&#x27;t place &#x27;Z&#x27;, so you are left with (k-2) choices. In the last position, you have to place number &#x27;1&#x27; to close the loop, so you have no choice. So, you have (k-1)(k-2)(k-3)...1 ways to form a loop, or (k-1)!.<p>Therefore, with a little bit of squinting, we can see that the probability that a random permutation has a loop on it of length exactly k is (k-1)!&#x2F;k!, or 1&#x2F;k.<p>We can formalize this argument as follows: There are (N choose k) ways to pick the k places on the permutation where there exists a cycle. There are (k-1)! valid ways to form a cycle on these k places. There are (N-k)! ways to arrange the remaining elements on the permutation. There are N! permutations, Therefore, P_loop(k, N) = (N choose k)<i>(N-k)!</i>(k-1)! &#x2F; N! = N! &#x2F; k! &#x2F; (N-k)! * (N-k)! * (k-1)! &#x2F; N! = 1&#x2F;k