TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

100 Prisoners, 100 lines of code

43 pointsby ulvundover 14 years ago

5 comments

aidenn0over 14 years ago
Here's a new brain teaser. The warden is a mathematician, and instead of arranging them randomly, he ensures that there is a cycle of at least 51. However he's not too cruel, so he tells the prisoners that he has done this.<p>I'm pretty sure that since this is less random than the original version the survival rate would go up, but I haven't figured out how to do this.
评论 #1653408 未加载
donaldcover 14 years ago
If the boxes are in a random jumble when the prisoner enters, there may be no practical way of having 100 prisoners consistently assign an ordering from 1 to 100 for the boxes. The approach outlined will then fail.<p>Were I a particularly evil warden, I could meticulously place all the boxes in the same such "jumble" after each prisoner left. One of the prisoners would certainly derive a different ordering of the boxes than one of the other prisoners. The approach might still have a better than random chance of succeeding, but it would be lower than that outlined in the article, since there are now two (or more) chances for a cycle of length greater than 50.
评论 #1657040 未加载
评论 #1654225 未加载
alphaBetaGammaover 14 years ago
For the people who would go for an analytical solution rather then monte-carlo: for a large number of prisoners the probability that they all find their numbers tends to 1 - ln(2) ~= 0.3069
评论 #1653257 未加载
Robin_Messageover 14 years ago
I'm not seeing any obvious trick here. Trying it with just two prisoners, two boxes and one look, I can't see a way to do better than chance. I'm just wondering if it's something like the two envelopes problem, where you can on average do better by switching based on a monotonic function of the amount in the first envelope. Perhaps there is a way of picking the boxes based on your number that does better than average, even if its just a little bit. Any hints?
评论 #1652496 未加载
评论 #1652325 未加载
评论 #1652421 未加载
D-Coderover 14 years ago
So the key idea is, if you get arrested, take a mathematician with you...