File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programming Diversions and the fly likes Only for those who don't know this riddle ... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "Only for those who don Watch "Only for those who don New topic
Author

Only for those who don't know this riddle ...

Vinod John
Ranch Hand

Joined: Jun 23, 2003
Posts: 162
There were 3 white hats and 2 black hats. The Jailor make three prisoners to sit one behind the other in such a way the first prisoner can't see any of the prisoners hat , the second one can see only the hat worn by the first and the third can see the hat worn by other two prisoner.
Now the Jailor blindfolds all the prisoners and make them were a hat and threw away the other two hats out of sight, and promise to free the prisoner who can figure out the color of hat he was wearing.
After few minute the first prisoner answers the question correct and was freed. What was the color of the hat he was wearing ?.
Ashok Mash
Ranch Hand

Joined: Oct 13, 2000
Posts: 1936
White.
How he got it right? Pure luck!


[ flickr ]
Greg Harris
Ranch Hand

Joined: Apr 12, 2001
Posts: 1012
because black and white are shades (not colors), the prisoner simply said, "my hat has no color."


what?
Greg Neef
Ranch Hand

Joined: Jun 16, 2003
Posts: 82
if the prisoner who can see two hats, sees two black ones his must be white.


SCJP 1.4
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4419
    
    5

I think there's more to the question than you gave. Doesn't the jailer take the blindfolds off after he puts the hats on the prisoners and don't the second and third prisoners both say "I don't know what color hat I'm wearing."? Then the first prisoner can deduce what color of hat he's wearing.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4419
    
    5

Originally posted by Greg Neef:
if the prisoner who can see two hats, sees two black ones his must be white.

You're on the right track here. You need to go down the line and carry it to it's logical conclusion.
You have to make the assumption that all three prisoners are smart and have thought out the situation fully and logically before they answer.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4419
    
    5

Originally posted by Ashok Krishnan:
How he got it right? Pure luck!

Nothing to do with luck. The first prisoner can answer with 100% certainty what color hat he is wearing.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
(P-prisoner, W-white, B-black)
I'm assuming P3 answers 1st, P2 next, P1 last.
If P3 answers W - he must see 2xB
P2 answers B
P1 answers B
If P3 answer is unsure - he sees 1xW and 1xB, or 2xW
If P2 answers W - he must see 1 x B
P1 answers B
If P2 answer is unsure - he must see W
P1 answers W
(If the clue is no-one but P1 answers, therefore P3 and P2 are unsure, then P1's answer would be W)
Vinod John
Ranch Hand

Joined: Jun 23, 2003
Posts: 162
Originally posted by Junilu Lacar:
Doesn't the jailer take the blindfolds off after he puts the hats on the prisoners

You are right I did miss that.
Originally posted by Junilu Lacar:

and don't the second and third prisoners both say "I don't know what color hat I'm wearing."? Then the first prisoner can deduce what color of hat he's wearing

I thought that would give more clue to solve the problem and also I added "After few minutes" that is actually that make it bit obvious that they don't know the answer.
Vinod John
Ranch Hand

Joined: Jun 23, 2003
Posts: 162
Originally posted by Ashok Krishnan:
White.
How he got it right? Pure luck!

So are you
but Mike explaination was perfect.
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Vinod : "I thought that would give more clue to solve the problem and also I added "After few minutes" that is actually that make it bit obvious that they don't know the answer"
WoW, whats the logic behind the way you think that.
What you thought obvious was very required and what you forget made the puzzle a more of a guess work.
[ August 22, 2003: Message edited by: Anupam Sinha ]
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1815
Actaully, most of the versions that I've heard have the prisoners/job applicants/whatever not answering for several minutes. The fact that no one is sure about anything gives you enough information to be sure. The other two don't actaully need to say anything; the fact that they have not said anything is enough.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Only for those who don't know this riddle ...
 
Similar Threads
China is at it again
prisoner problem
Which Pattern Should I Implement?
Puzzle of the night
Puzzle