Five hats and four logicians in a circle

I found this question in a book. The solution is correct (and complicated). No tricks involved.

Four men were seated around a table. They were blindfolded and a colored hat was placed on each of their heads. They were told a true statement "The hats on your heads were chosen from 2 white hats, 2 black hats and 1 red hat" Then the fifth hat was taken away and the blindfolds were removed.

Each logician was asked to name the color of their hat. If they could logically do so, they did, otherwise said "I don't know". The question was repeated to each of them in circular fashion (more than once, if need be) until only one of them failed to name the color of his own hat. The red hat was not given, but the logicians didn't know this.

Which logician failed to name the color of his hat even when the other three had? (Was it the man who was asked the first question, the man who was asked the second question, the man who was asked the third question, or the man who was asked the fourth question?)

• I'll have to say, this is quite the hat trick. Mar 25 '15 at 13:25
• When asked in order, do they tell the other logicians what their hat is? And what if, after the first guy names his hat, the three others name there's immediately after? Mar 25 '15 at 13:37
• ... and then a guru comes in to say, "I see at least one white hat". :P Mar 25 '15 at 14:01
• @Lawrence And they all have bowls of spaghetti, with forks between them. Each one can only eat when he holds both the left and right forks... Mar 25 '15 at 21:15
• Of course, this relies on logicians being strange people... anyone normal, when asked the colour of their hat and not knowing it, would take the hat off and look at it. Mar 26 '15 at 20:41

Call the logicians A, B, C, and D, in the order they speak. WLOG, say A is wearing a white hat. Note that each logician sees 2 black, 1 white if he's wearing white or 2 white, 1 black if he's wearing black, so he always knows his own hat is either [the colour it actually is] or red.

A is wearing white and sees 2 black, 1 white. As far as he knows, he could be wearing either white or red. He says, "I don't know."

Case 1: B is also wearing white

B is wearing white and sees 2 black, 1 white. If B were wearing red, then A (seeing 2 black, 1 red) would have been able to identify his own colour. So B says, "My hat is white."

C is wearing black and sees 2 white, 1 black. If C were wearing red, then B (seeing 1 white, 1 black, 1 red) would still have known his hat was white, since B wearing black would be inconsistent with A's answer (A would then have seen 1 red and 2 black and known he was wearing white). So C says, "I don't know."

D is wearing black and sees 2 white, 1 black. If D were wearing red, then C would have seen 1 red and 2 white and known his own colour. So D says, "My hat is black."

A is still wearing white, and argues as follows. If A were wearing red, then B would have seen 2 black, 1 red and known B was wearing white; C would have seen 1 black, 1 red, 1 white and known C was wearing black (if C were white, B would have seen 1 white, 1 black, 1 red and either black or white for B would have been consistent with A's answer); contradiction, so A says, "My hat is white."

In this case, the answer is C.

Case 2: B is wearing black, C is wearing white

B is wearing black and sees 2 white, 1 black. If B were wearing red, then A would have seen 1 black, 1 white, 1 red and still said "I don't know". So B says, "I don't know."

C is wearing white and sees 2 black, 1 white. If C were wearing red, A would have seen 2 black, 1 red and known his own colour. So C says, "My hat is white."

D is wearing black and sees 2 white, 1 black. If D were wearing red, B would have seen 2 white, 1 red and known his own colour. So D says, "My hat is black."

A is still wearing white, and argues as follows. If A were wearing red, then B would have seen 1 white, 1 black, 1 red and either black or white for B would have been consistent with A's answer; C would have seen 2 black, 1 red, and known C was wearing white; D would have seen 1 white, 1 black, 1 red and known that he was wearing black (if D were white, B would have seen 2 white, 1 red and known B was wearing black). So A says, "I don't know."

B is still wearing black, and argues as follows. If B were wearing red, then A would have seen 1 white, 1 black, 1 red and not known his own colour; B would have said what he did; C would have seen 1 white, 1 black, 1 red and known he was wearing white (if C was wearing black, A would have seen 2 black, 1 red and known his own colour); D would have seen 2 white, 1 red and known he was wearing black; and finally A would still not have known his colour (if A was wearing black, everything would have happened the same way it did!). So B says, "I don't know."

C and D still know their colours.

A is still wearing white, and argues as follows. If A were wearing red, then as above, B, C, D, and A (second time round) would still have responded as they did, and then B (seeing 1 white, 1 black, 1 red) would still not have known his own colour (if B were wearing white, then we have RWWB and everything goes through as before!) So A says "I don't know" for the third time.

B is still wearing black and argues as follows. If B were wearing red, then as above, the first and second rounds would have gone as they did, and then A (seeing 1 white, 1 black, 1 red) would still not have known his own colour (if A were wearing black, then we have BRWB and everything goes through as before!). So B says "I don't know" for the third time.

The same argument goes on. No new information is gained by anyone.

Case 3: B and C are both wearing black

As argued above, B is wearing black and says, "I don't know."

C is wearing black and sees 2 white, 1 black. If he were wearing red, B would have seen 2 white, 1 red and known his own colour. So C says, "My hat is black."

D is wearing white and sees 2 black, 1 white. If he were wearing red, A would have seen 2 black, 1 red and known his own colour. So D says, "My hat is white."

A is still wearing white, and argues as follows. If A were wearing red, then B would have seen 1 white, 1 black, 1 red and either black or white for B would have been consistent with A's answer; C would have seen 1 black, 1 white, 1 red, and known C was wearing black (if C were white, B would have seen 2 white, 1 red and known B was wearing black); D would have seen 2 black, 1 red and known that he was wearing white. So A says, "I don't know."

B is still wearing black, and argues as follows. If B were wearing red, then A would have seen 1 white, 1 black, 1 red and not known his own colour; B would have said what he did; C would have seen 2 white, 1 red and known he was wearing black; D would have seen 1 white, 1 black, 1 red and known he was wearing white (if D was wearing black, A would have seen 2 black, 1 red and known his own colour); and finally A would still not have known his colour (if A was wearing black, everything would have happened the same way it did!). So B says, "I don't know."

C and D still know their colours.

A is still wearing white, and argues as follows. If A were wearing red, then as above, B, C, D, and A (second time round) would still have responded as they did, and then B (seeing 1 white, 1 black, 1 red) would still not have known his own colour (if B were wearing white, then we have RWBW and everything goes through as before!) So A says "I don't know" for the third time.

B is still wearing black and argues as follows. If B were wearing red, then as above, the first and second rounds would have gone as they did, and then A (seeing 1 white, 1 black, 1 red) would still not have known his own colour (if A were wearing black, then we have BRBW and everything goes through as before!). So B says "I don't know" for the third time.

The same argument goes on. No new information is gained by anyone.

In Cases 2 and 3, A and B never find out their colours; C and D will just sit there snickering at them forever. But we're told in the OP that eventually "only one of them failed to name the color of his own hat", so we can deduce the following two pieces of information:

• the first two logicians to speak have the same colour of hat, as do the last two
• the third logician is the last one not to know his own colour.

First observations

Since the puzzle is symmetric in white and black hats, I assume that the first man has a black hat. Then only three cases remain: (1) BWWB; (2) BWBW; (3) BBWW.

($\ast$) If a man sees two hats of color white, then he knows that his hat is either red or black. If a man sees two hats of color black, then he knows that his hat is either red or white.

(Case 1) Suppose that the four men have hats BWWB.

• The first man concludes from (*): I have either R or B.
• Then the second man concludes from (*): I have either R or W.
• Then the third man concludes from (*): I have either R or W. If I have R, then the second man would have been able to derive his color. Hence I have W. Bingo!
• Then the fourth man concludes from (*): I have either R or B. If I have R, then the first man would have been able to derive his color. Hence I have B. Bingo!
• Then the first man thinks: I have either R or B. If I have R, then the fourth man would see RWW?, and know his color; the third man would see RW?B, and know that he has W, since the second guy was not able to deduce his color. If I have B, then the third and fourth man are able to deduce their colors (as discussed above). Hence I still do not know my color.
• Then the second man thinks: I have either R or W. If I have R, then the fourth man would see BRW?; he would know that the first man did not see W on him (as otherwise he would have deduced B for himself); hence the fourth man deduces his color. Furthermore, the third man would see BR?B, and deduce his color W. In case I have W, then the third and fourth man are able to deduce their colors (as discussed above). Hence I still do not know my color.
• From this moment on, no further information is gained by anybody. The game is stuck. Contradiction.

(Case 2) Suppose that the four men have hats BWBW.

• The first man concludes from (*): I have either R or B.
• Then the second man concludes from (*): I have either R or W.
• Then the third man concludes from (*): I have either R or B. If I have R, then the first man would have been able to derive his color. Hence I have B. Bingo!
• Then the fourth man concludes from (*): I have either R or W. If I have R, then the second man would have been able to derive his color. Hence I have W. Bingo!
• Then the first man thinks: I have either R or B. If I have R, then the third man would see RW?W, and know his color; the fourth man would see RWB?, and know that he has W, since the third guy was able to deduce his color. If I have B, then the third and fourth man are able to deduce their colors (as discussed above). Hence I still do not know my color.
• Then the second man thinks: I have either R or W. If I have R, then the third man would see BR?W; he would know that the first man did not see W on him (as otherwise he would have deduced B for himself); hence the third man deduces his color. Furthermore, the fourth man would see BRB?, and deduce his color W. In case I have W, then the third and fourth man are able to deduce their colors (as discussed above). Hence I still do not know my color.
• From this moment on, no further information is gained by anybody. The game is stuck. Contradiction.

(Case 3) Suppose that the four men have hats BBWW.

• The first man concludes from (*): I have either R or B.
• Then the second man concludes from (*): I have either R or B. If I have R, then the first guy would see ?RWW and deduce his color. Hence my color is B. Bingo!
• Then the third man concludes from (*): I have either R or W. If I have R, then the first man sees ?BRW and would not know his color; the second man would see B?RW and know that his color is not W (as otherwise the first man would have deduced his color); hence the second man would deduce his color B. If I have W, then the first and the second man would behave as explained above. Hence I still do not know my color.
• The fourth man concludes from (*): I have either R or W. If I have R, then the third man would see BB?R and deduce his color. Hence I have W. Bingo!
• Then the first man concludes from (*): I have either R or B. If I have R, then the third guy would see RB?W; since the second guy could deduce his color, he must see two white hats; the third guy knows this and would deduce his color W. Hence I have not R and my hat is B. Bingo!
• The second guy already knows.
• Then the third man concludes from (*): I have either R or W. If I have R, then the fourth man would see BBR? and deduce his color W. The first man would sees ?BRW, and know that the fourth man was able to deduce his color; hence the fourth man must see two Bs and the first man would know his color. If I have W, then the others would behave as in the steps explained above. Hence I still do not know my color.
• From this moment on, no further information is gained by anybody. The third guy never learns his hat color.

Answer: The only case that is compatible with the problem statement is case 3, where the first and second guy have the same hat color (black or white) and the third and fourth man have the opposite hat color (white or black). In this case the first, second and fourth man are able to deduce their colors, but the third man will never be able to deduce his color.

• In case 3 during the second turn for the third man, he could be R or W. If he had R, then the first man would not be able to deduce his color. This would mean that the third man is W. Your problem is in the statement, "Hence the fourth man must see two Bs". The fourth man can also deduce his color if he sees two Ws (the hats are WBRW) because if the fourth man had B then the first man would have known his own color, but the first man cannot in that scenario. Mar 25 '15 at 23:17
• @ShadowCat7 In WB_W, the only way for #2 to know he's B is if #3 is R. As soon #3 says "I don't know," the group can discount WBRW. And we're back to "hence the fourth man must see two Bs." Mar 26 '15 at 1:04
• @ghosts_in_the_code This answer is essentially a copy of mine, which was posted first. Mar 27 '15 at 1:35
• @randal'thor Thanks for telling me, I've accepted yours now. Mar 27 '15 at 15:34

I've seen several correct solutions, but here's a different method.

Solution:

The third logician is the one who cannot determine the color of their hat.

It is evident that the problem is symmetric with respect to Black and White hats; that is, the situation is logically identical if black and white hats are interchanged. That leaves fifteen possible scenarios which one of the logicians might entertain. I have enumerated them (including black/white interchanges) in the table below.

Each logician, based on the three hats which he sees, will be able to narrow the field down to at most two potential scenarios. In the scenarios in which the logician sees one red hat and two hats which are either both black or both white, he will be able to deduce that his own hat is white or black, respectively. When the logician's direct observations do not give them this information, then further deduction is based on the answers of the other logicians. For the purposes of the puzzle, we as usual assume that the logicians have mutual full confidence in the abilities of the other logicians, ad infinitum.

In the table below, the columns labeled 1, 2, 3, 4, 1 represent whether each logician in turn will be able to answer the question. If they are unable, the table shows a period. If they are able due to the colors of the three hats they personally observe, as described above, then the table shows the number 0. If the responses that the other logicians would have given in the only other scenario consistent with the direct observations is different from the responses given in the scenario under consideration (which is easily determined from inspection of the rows of the table), then the number of the row representing the other scenario appears in the table. If the logician in question already answered on the previous round, the table shows a hyphen.

1 2 3 4 1
1 WWBB/BBWW . 12 . 2 15
2 WWBR/BBWR . 7 0 1 .
3 WWRB/BBRW . 9 . 0 8
4 WBWB/BWBW . . 9 5 .
5 WBWR/BWBR . 0 7 4 .
6 WBBW/BWWB . . 8 7 .
7 WBBR/BWWR 0 2 5 6 -
8 WBRW/BWRB . 0 6 9 3
9 WBRB/BWRW 0 3 4 8 -
10 WRWB/BRBW . . 12 0 .
11 WRBW/BRWB . . 0 12 .
12 WRBB/BRWW 0 1 10 11 -
13 RWWB/RBBW . . 15 0 .
14 RWBW/RBWB . . 0 15 .
15 RWBB/RBWW . 0 13 14 .

Note that the scenarios in which only the first logician is unable to guess their hat color after the other three logicians have correctly answered (2, 5, 15) all have the same pattern of answers, and so the first logician will not be able to distinguish them. Likewise, the scenarios in which, after the first logicians second turn, both the first and second logicians still do not know their hat colors (4, 6, 10, 11, 13, 14), and the scenarios in which, after the first logician's second turn, the third logician still does not know their hat color (1, 3). Therefore, continued questions will not yield any new information in these scenarios.

Only three scenarios, numbered 1, 4, and 6 (marked with asterisks in the table), do not have a red hat, and so are consistent with the problem statement. Of these, scenarios 4 and 6 have an outcome in which two of the logicians are unable to deduce their hat color. Only scenario 1, in which the first, second, and fourth logicians are successful, but the third is not, meets the condition in the problem statement.

Ok, we have 2 hat placements: same color next to each other, or same color across.

If same color across (assume black hat asked first):
The only way to be the first person and know your hat is to see 2 of the same color and the red hat.

• First person (sees white, white, black): IDK
• Second (bbw): IDK
• Third (wwb): Knows that the black hat across from him didn't see a red hat on his head, Black
• Fourth (bbw): Same as third, but White
• First (wwb): Knows that he has black or red. Second's answer doesn't help (could see wbr), neither does third (could see wwr) nor fourth (could see wbr and determine that second also has wbr). IDK
• Second (bbw): if red, then first's idk, third's I know, and fourth's I know are all reasonable. IDK
• Stuck.

And the colors sitting next to each other (go order BBWW):

• First (wwb): IDK
• Second (wwb): Sees the same WW that first did, knows he's not R, so Black
• Third (bbw): Sees the same WB that first did, IDK
• Fourth (bbw): Sees the same BB that third did, knows he's not R, so White
• First (wwb): knows second could have seen red or black and gotten his hat, knows it doesn't matter for third, but knows fourth had to see some dupe. Since first already sees the ww dupe, he knows his hat is Black
• Third (bbw): uses same logic as first to get his hat as White

For the sake of completeness, lets' go with a variant of scenario 2 (order BWWB):

• First (wwb): IDK
• Second (bbw): IDK
• Third (bbw): Sees the same BB that second did, know's he's not R, so White
• Fourth (wwb): Sees the same WW that first did, know's he's not R, so Black
• First (wwb): Knows that both second and third saw BWX, and both of them see BWX, and the second one knows something the first doesn't, which is that both of them see a pair. He would think he is black, but then if he were R, then third would know why second was stuck, and fourth would know his color straight up. IDK
• Second (bbw): If he were R, then third's declaration would be the same, as would fourth's (based on first). IDK
• Stuck
• So in scenario 1, it's the 2nd person, in scenario 2, it's the 1st person Mar 25 '15 at 16:09
• Scenario 2 it's the 3rd who is the last to know. I suppose it changes if you go BWWB instead. Mar 25 '15 at 16:17
• I think there's a logical error in the BWWB case. Can you expand on how "First" comes to the conclusion that he is black? Because @Gamow's answer seems to justify that "First" still can't know. I think you need to refute his logic. Mar 25 '15 at 20:09
• Your first case (BWBW) is wrong, the statement "[#4's answer] indicates [#1's] color is the same as the guy's across" is false. If #1 wore red, the first four steps remain the same (#4 would still answer white, he'd know he's not black or else #2 would have known his color). So, #1 can't know his color yet. Mar 25 '15 at 20:16
• (BBWW) Third. Sees 2 blacks and a white, due to #2 knowing he was black means #2 saw 2 whites. Therefore says White Mar 25 '15 at 20:19

Solution:

The third person to say what color his hat was. The first man's hat was the same color as the second man's hat, and the third man's hat was the same color as the fourth's.

Process:

Here's an attempt at a more intuitive way to solve this. First, we add in a round zero in which we determine what everyone knows based only on the hats they can see. Then, we eliminate possibilities based on which possible situations the current situation matches.

We'll call the logicians A, B, C, and D. To reduce the size of the table I'm going to build, we'll say WLOG that A is wearing a white hat and also go through the first round in a normal fashion.

Case 1: A and B are wearing white hats

Round 1 (WWBB):

• A -> I see _WBB. I could have white or red. "I don't know."
• B -> I see W_BB. If I had red, A would see RBB and know A has W. A didn't know, so "I have a white hat".
• C -> I see WW_B. I have black or red. If I have red, then A sees _WRB and doesn't know. B sees W_RB and knows if B had black A would know so B has white. If I have black... (real scenario). "I don't know."
• D -> I see WWB_. If I had red, C would see WW_R and know C has black, so "I have a black hat."

So going forward A and C only need to consider scenarios where B and D have white and black hats respectively.

Case 2: A and C are wearing white hats

Round 1 (WBWB):

• A -> I see _BWB. I could have red or white. "I don't know."
• B -> I see W_BW. I could have red or white. If I have red, A sees _RWB and can't tell. If I have white, A sees _BWB and can't tell. "I don't know"
• C -> I see WB_B. If I had red, A would have known. So "I have a white hat."
• D -> I see WBW_. If I had red, B would have known. So "I have a black hat."

So going forward A and B only need to consider scenarios where C and D have white and black hats respectively.

Case 3: A and D are wearing white hats

Round 1 (WBBW):

• A -> I see _BBW. I could have red or white. "I don't know."
• B -> I see W_BW. I could have red or black. "I don't know."
• C -> I see WB_W. If I had a red hat, then B would have seen W_RW and known. So "I have a black hat."
• D -> I see WBB_. If I had a red hat, then A would have seen _BBR and known. So "I have a white hat."

So going forward A and B only need to consider scenarios where C and D have black and white hats respectively.

Table for Case 1

We'll denote turns by a round number and whose turn it is. We'll also use round 0 to represent what they can figure out without anyone saying anything. Note: I'm building this tables by running through the first round of the hypothetical situation.

Hats 0A 0B 0C 0D 1A 1B 1C 1D
WWBB ? ? ? ? ? W ? B
WWRB ? ? ? B ? W ? B
BWWB ? ? ? ? ? ? W B
BWRB ? W ? ? ? W R B
RWWB ? ? ? B ? ? W B
RWBB ? W ? ? ? W B B

Looking at the table, we can see that A can easily figure out that A doesn't have a red hat - otherwise either B wouldn't have known or C would have. So A says "I have a white hat."

Hats 0A 0B 0C 0D 1A 1B 1C 1D 2A
WWBB ? ? ? ? ? W ? B W
WWRB ? ? ? B ? W ? B W
BWWB ? ? ? ? ? ? W B ?
BWRB ? W ? ? ? W R B B
RWWB ? ? ? B ? ? W B ?
RWBB ? W ? ? ? W B B R

Now that A knows, C is stuck. There's no way for C to distinguish between having a red hat and a black hat. So C, the third logician to speak, doesn't know the color of his hat.

Table for Case 2

Hats 0A 0B 0C 0D 1A 1B 1C 1D
WBWB ? ? ? ? ? ? W B
WRWB ? ? ? B ? ? W B
BWWB ? ? ? ? ? ? W B
BRWB ? ? W ? ? ? W B
RWWB ? ? ? B ? ? W B
RBWB ? ? W ? ? ? W B

Here, A and B are both stuck. They have no information to distinguish between any of these cases. This does not match the OP's description, so this must not have been the case.

Table for Case 3

Hats 0A 0B 0C 0D 1A 1B 1C 1D
WBBW ? ? ? ? ? ? B W
WRBW ? ? B ? ? ? B W
BWBW ? ? ? ? ? ? B W
BRBW ? ? ? W ? ? B W
RWBW ? ? B ? ? ? B W
RBBW ? ? ? W ? ? B W

Again, both A and B are stuck so this is not the scenario. Thus, only case 1 remains and must be what happened.

Call the logicians with white hats W1, W2 in that speaking partial order, and likewise B1, B2 for those with black hats. Without loss of generality, start with W1.

W1 sees 2B 1W, so his own could be R or W and says IDK. Reverse-engineering his answer and knowing W1's hat colour, W1 could say IDK only if he saw 1R 1W 1B or 2B 1W.

W2 says W at his turn because he sees 2B and knows W1 also saw 2B (so W1 saw 2B 1W). Reverse-engineering his answer and knowing W2's hat colour, W2 could say W only if he saw 1R 2B or 1W 2B.

B1 and B2 deduce W2 saw 2B by reverse-engineering, so each seeing 2W 1B says B. Reverse-engineering Bx's answers and knowing Bx's hat colour, Bx could say B only if he saw 2W 1B or 1R 1W 1B.

W1 sees 2B 1W and even with the other answers, cannot tell from the reverse-engineered answers of the others whether his own is R or W since all 3 other answers would have remained the same even if they saw W1 wearing R.

Answer: the first to speak cannot tell his own hat colour even when the other 3 had.

I know it's not exactly the spirit in this community, but if anybody's interested in solving the puzzle with a computer program, here's a nice Python code:

WHITE = 0
BLACK = 1
RED = 2
DONT_KNOW = 3

COLOURS = [WHITE, BLACK, RED]
QUANTITIES = {WHITE: 2, BLACK: 2, RED: 1}
ANNOUNCEMENTS = {WHITE: 'White', BLACK: 'Black', RED: 'Red', DONT_KNOW: "Don't know"}

"""
This function gets a player's identity, the round number, the three hats the player
can see and the history of announcements, and returns the player's announcement.

player: 0, 1, 2 or 3
round: a non-negative integer (0, 1, 2 ...)
view: a list of four colours (WHITE, BLACK or RED)
(the own player's colour is disregarded)
history: a list of players, each one is a list of rounds,
each one is the relevant announcement
output: WHITE, BLACK, RED or DONT_KNOW
"""

real_view = [view[p] for p in range(4) if p != player]
view_count = dict([(colour, real_view.count(colour)) for colour in COLOURS])

possible_hats = [colour for colour in COLOURS
if view_count[colour] < QUANTITIES[colour]]

assert len(possible_hats), "Bug - no possible hats."

if len(possible_hats) == 1:
return possible_hats[0]

consistency = dict([(pos, True) for pos in possible_hats])
for possible_hat in possible_hats:
for player_check in range(4):
expected_view = view[:]
expected_view[player] = possible_hat
for round_check in range(min(len(history[player_check]), round + 1)):
if (round_check == round) and (player_check >= player):
break
expected_view, history)
if expected_announcement != history[player_check][round_check]:
consistency[possible_hat] = False
break
if not consistency[possible_hat]:
break

assert sum(consistency.values()), "Bug - no consistent choice."

if consistency.values() == [True, True]:
return DONT_KNOW

return consistency.keys()[consistency.values()[1]]

def play(hats, pr=True):
"""
This function gets the four distributed hats
and returns the announcements by order.

hats: a list of four colours (WHITE, BLACK or RED)
(not more than 2, 2 and 1 of them, respectively)
"""

history = [[] for _ in range(4)]
got_it = {}

player = 0
round = 0
oldest_dont_know = -1
more_info = True

while more_info or (oldest_dont_know != player):
if (not round) or (history[player][-1] == DONT_KNOW):
if pr:
print "Player #%d says: %s!" % (player + 1, ANNOUNCEMENTS[answer])
more_info = True
elif more_info:
oldest_dont_know = player
more_info = False
player = (player + 1) % 4
if not player:
round += 1

return got_it


...and some outputs:

>>> an1 = play([WHITE, WHITE, BLACK, BLACK])
Player #1 says: Don't know!
Player #2 says: White!
Player #3 says: Don't know!
Player #4 says: Black!
Player #1 says: White!
Player #3 says: Don't know!

>>> an1 = play([WHITE, BLACK, BLACK, WHITE])
Player #1 says: Don't know!
Player #2 says: Don't know!
Player #3 says: Black!
Player #4 says: White!
Player #1 says: Don't know!
Player #2 says: Don't know!

>>> an1 = play([WHITE, BLACK, WHITE, BLACK])
Player #1 says: Don't know!
Player #2 says: Don't know!
Player #3 says: White!
Player #4 says: Black!
Player #1 says: Don't know!
Player #2 says: Don't know!


As you see (and people have said), in the first scenario only player #3 can't figure out his own colour. In the two other scenarios only players #3 and #4 can.

• If you had written this code before the puzzle was manually solved, you would have definitely got some up-votes. Using computers is not against the spirit of the site (we even have a computer-puzzle tag), it's just that a logical non-computer answer will always be preferred. If no such answer has been posted yet, please feel free to write code. Feb 26 '16 at 14:09

1: he sees 2W and 1B. He might have R or B, so he passes 2: he sees either 2W and 1B or 2B and 1W. Knowing the first one passed, he can make the following statements:

1. If 3 and 4 have same color of the hat, he has the opposite(if he would have R, 1 would have guessed his color)
2. If 3 and 4 have different colors, his color is opposite of 1 or R

Let's move on with scenario 1:

• 3 sees that 2 guessed his color, and 1 passed. That means that he doesn't have R(otherwise 2 wouldn't be able to guess), so he has either B or W. He can just count and guess his hat right
• 4 sees that 2 and 3 guessed their colors, so his color isn't R(otherwise they wouldn't be able to guess their colors). So he has either B or W, count and win
• 1 sees that they all guessed their colors. If he would have R, 3 wouldn't be able to guess his hat, so 1 can also easily guess his color

So in scenario 1 they all win.

Scenario 2:

• 2 passes, because he isn't sure if he has opposite of 1 or R
• 3 makes a guess and says his hat is same as 1. Because if he would have R, 1 would easily guess his hat
• 4 guesses too(same logic as 3)
• 1 guesses correctly, because if he would have R, 4 wouldn't be able to guess his hat
• 2 can guess it too, because if he would have R, 3 wouldn't be able to guess his color

So if they all think logically, they will all be able to guess their colors

There are 2 cases:

1. Red doesn't get dropped.
2. Red does get dropped.

CASE 1
If we call the people A,B,C,D, then we have a situation like this:
A-> RED
B-> WHITE
C -> BLACK
D -> WHITE or BLACK (suppose white, it's the same)

They can see the others' hat, but not their own one. So, they decide to say "I don't know" unless one of them is sure of what he's saying. C can see 2 white hats and a red one, so he deduces that his hat is black. The others now deduce that C didn't see any black hat, so A,B and D can now deduce their colors just looking at the others. The loser in this case is the man who's asked after the other two.

CASE 2

A-> WHITE
B-> WHITE
C -> BLACK
D -> BLACK

Nobody speaks about his hat, so they all deduce that this is not a CASE 1. Easily, everyone understand that his hat is white if he sees 2 black hats, otherwise his cap is black. The loser in this case is, again, the one who's asked as last.

• It's about who fails to answer before the other 3 answer, and also " The red hat was not given, but the logicians didn't know this." Mar 25 '15 at 16:11
• Edited the part about the winners and the losers. The men always start assuming it's case 1; if nobody answers, they deduce it's CASE 2 and not CASE 1 Mar 25 '15 at 16:18

L1, L2, L3, and L4 are asked in order. We know that each logician sees two hats of the same colour and one of a different colour, but let's see what they discover.

L1 looks around the table and sees one of the following combinations:

L1 WR WR WR BR BR BR BW BW BW BW BW BW || W W W B B B
L2 B B W B W W W B B R R W || R B B R W W
L3 B W B W B W B W R B W R || B R B W R W
L4 W B B W W B R R W W B B || B B R W W R

Because the only scenarios where L1 can guess his hat colour are scenarios where someone at the table is wearing a red hat, we'll skip the discussion on them. L1 is unable to guess his hat colour.

L2 looks around the table and sees one of the following combinations. Combining the information provided by L1, he deduces the following information about himself:

1 2 3 4 5 6
L1 B B B W W W
L2 WR WR B BR BR W
L3 B W W B W B
L4 W B W W B B

In scenario 2 and 6, he is able to accurately guess the colour of his hat. If he is able to do this, L3 and L4 are also able to deduce the colours of their hats are the same and opposite of whatever L2 said, but L1 is left wondering if his hat might still be red or the same as L2.

Moving on to consider 1, 3, 4, and 6 where L2 was unable to guess, L3 sees the following:

L1 B B B W W W
L2 B W W B W B
L3 WR WR B BR BR W
L4 W B W W B B

Removing the scenarios made that don't fit scenario 1, 3, 4, or 6:

7 8 9 10 11 12
L1 B B B W W W
L2 B W W B W B
L3 R WR B BR R W
L4 W B W W B B

L3 is able to guess his hat colour in scenario 7, 9, 11, and 12. In 7 and 11 when L3 is wearing red (it's not important that we know this doesn't happen), L2 and L4 know that they are wearing opposite colour hats. In 9 and 12, they know they are wearing the same as each other and opposite to whatever L3 has said. L1 is still left in the dark.

Finally, we consider the remaining two scenarios in which L3 did not guess. We once again start with the table that L4 sees.

L1 B B B W W W
L2 B W W B W B
L3 W B W W B B
L4 WR WR B BR BR W

When we eliminate the combinations that we know do not fit scenarios that would have otherwise already been answered by the other logicians, we're left with:

13 14
L1 B W
L4 W B
L3 W B
L2 B W

From the results of the other logicians, L4 is now sure that the colour of his hat now matches L1's hat. L1 still thinks his hat might be red, though.

We reduce possibilities by assigning X either "black hat" or "white hat" and Y the remaining. Furthermore R represents "red hat"; ? or IDK stands for "I dont know". Thus a number of theoretical combinations have to be considered while in reality only three combinations can occur.

By considering what each logician would have guessed given the possible combinations, we can eliminate possibilities with each new answer, even when it is IDK.

theoretical        practical
RRRXXXXXXXXXXXX    XXX
XXXRRRXYYXYYXYY    XYY
XYYXYYRRRYXYYXY    XYX
YYXYXYYXYRRRYYX    YYX

possible options for A:
RRRXXX
XXXXYY
XYYYXY
YYXYYX

possible options for B:
XXXXXX
RRRXYY
XYYYXY
YYXYYX

possible options for C:
XXXXXX
XYYXYY
RRRYXY
YYXYYX

possible options for D:
XXXXXX
XYYXYY
YYXYXY
RRRYYX


The question for each logician is basically reduced to "Am I R?".

A_1: theoretical

RRRXXXXXXXXXXXX
XXXRRRXYYXYYXYY
XYYXYYRRRYXYYXY
YYXYXYYXYRRRYYX

?????X??X??X???


Since there is no R, A_1 will always answer IDK, eliminating three possibilities.

B_1: possible options for B:

XX.XXX
RR.XYY
XY.YXY
YY.YYX

theoretical        practical
RRRXX.XX.XX.XXX    XXX
XXXRR.XY.XY.XYY    XYY
XYYXY.RR.YX.YXY    XYX
YYXYX.YX.RR.YYX    YYX

?X???.?Y.?Y.X??


B_1 can only either answer X for ??YY or IDK, eliminating further two possibilities.

C_1: possible options for C:

X..XXX
X..XYY
R..YXY
Y..YYX

theoretical        practical
RRRXX.X..X..XXX    XXX
XXXRR.X..X..XYY    XYY
XYYXY.R..Y..YXY    XYX
YYXYX.Y..R..YYX    YYX

theoretical answers ( B_1 == X )
.Y..........Y..

theoretical answers ( B_1 == IDK )
X.YXY.R..Y...XY


D_1: possible options for D:

X..XXX
X..XYY
Y..YXY
R..YYX

theoretical        practical
RRRXX.X..X..XXX    XXX
XXXRR.X..X..XYY    XYY
XYYXY.R..Y..YXY    XYX
YYXYX.Y..R..YYX    YYX

theoretical answers ( B_1 == X )
.Y..........Y..

theoretical answers ( B_1 == IDK, C_1 = X )
Y..Y.........Y.

theoretical answers ( B_1 == IDK, C_1 = Y )
..X.X....R....X


A_2: theoretical

RRRXX.X..X..XXX
XXXRR.X..X..XYY
XYYXY.R..Y..YXY
YYXYX.Y..R..YYX

theoretical answers ( B_1 == X )
.?..........?..

theoretical answers ( B_1 == IDK, C_1 = X, D_1 = Y )
?.?XX........??


A_2 still can only answer IDK, thereby eliminating 2 further possibilities were it would have answered X.

B_2: possible

...XXX
...XYY
...YXY
...YYX

theoretical answers ( B_1 == IDK, C_1 = X, D_1 = Y )
....YY


In conclusion, no matter if logician B needs one or two turns, the first logician will always be the one who fails to get the correct answer.

B       W     I will enumerate this table as    1       2
B       W                                       4       3

• First logician looks at the others and says "I don't know."
• Second one looks at they all and thinks "If first one didn't know about it, it indicates that he thinks that he can be a red. If he thinks that but he wears black, it means that I cannot be a red in any way. If I am not a red, and there is two blacks and one white, I must be a white.
• Third one sees the thinks the same and says "I'm white."
• And fourth one says "I'm black".

From this example, you see that the first logician failed to name while the others didn't. Rotating and checking for all cases, one is able to conclude that the first logician is always the one who fails while the three others don't. Why? Because the first one holds the uncertainty and solve it by saying "I don't know.". Then, the others have the clue needed to fix the 50% of probability problem.

----- Edit -----

B       W     I will enumerate this table as    1       2
B       W                                       4       3

• First one is black looks at all and says "I don't know".
• Second one is white looks at all and says "I don't know".
• Third one thinks:

First one is black but doesn't know. Second one also doesn't know. First and third and black, while second is white. I can only be white or red. If second one can't affirm that he is white, it is because I cannot be a red. Then, my hat is white.

When the third one gives his answer, the other three have the clue needed to solve the problem. Then, the one that will be considered to fail while the three others didn't is the second one.

• I think the first solution is the best one, since I believe that the second logician could apply the reasoning applied by the fourth one of the second case. Mar 25 '15 at 15:15
• I think there's a logical flaw here: "Second...If first one didn't know about it, it indicates that he thinks that he can be a red.". This doesn't follow; 2 could think he were R, meaning from 2's perspective, 1 could have seen one of each color and thought he was B or W, but not R. Mar 25 '15 at 17:42
• First one can't think that he can be a white, because he sees second and third ones with white hats. Mar 25 '15 at 17:59
• But the point is, #2 doesn't know that. All #2 knows is that #1 either saw BWW, or BWR. #2 has no reason to believe that #1 didn't see BWR. So he can't conclude that he's not an R. Mar 25 '15 at 18:00
• Excuse me? If they could talk to each other outside the allowed responses, they could just say "you are wearing white". Mar 25 '15 at 18:27

W: White B: Black

Here's how it goes:

• First (wwb): This guys sees 1 black and 2 whites. 50-50 chance of being black/red. Says I don't know
• Second (wwb): Sees exactly what #1 sees, but knows that the first didn't know if he was red, therefore didn't see red, meaning he must be black. He says Black
• Third (bbw): Sees 2 blacks and 1 white. 50-50 chance of being white/red. But, knowing #2 knew he was black, this means he must have saw 2 whites, otherwise he wouldn't know if he's white or not. Therefore he must be white. He says White
• Fourth (bbw): He sees 2 blacks and 1 white. Meaning 50-50 chance of being white/red. However, using the same logic as #3, he can deduce that he is white. He says White.

Therefore, the answer to your question, is the first logician. Sequence: BBWW.

• What? This is just wrong. The answer is the third logician - see my answer or Gamow's copy of it. Mar 25 '15 at 21:52
• This is not quite correct. If second sees that third is white, and fourth is black, he cannot say for certain that he is not red. So he would have to answer I don't know in this scenario.
– Kami
Mar 25 '15 at 23:39