# Guessing hat colors. 4 prisoners

This is a variant about guessing hat colors. You may want to try Hats and alien or Guessing hat colors or Four prisoners wearing black and white hats.

Statement

4 prisoners are to be executed. The warden proposed a new challenge: he will distribute four hats amongst them, chosen from two colors at most. One hat will be distributed to each prisoner and they won't be able to see their own (but they will see each other's hats).

They will have to state the color of their own hat, all at the same time. They will be released if all their answers are True or if all their answers are False.

Question

As they have one night to prepare their strategy, is there a way they can be released for sure?

EDIT: Prisoners are not aware of the colors, they can't communicate with each other after the hats are distributed. And there is no predetermined number of hats of each color (could be 0-4, 1-3 or 2-2). They also have to announce one of the one or two colors chosen by the warden, otherwise they will be executed.

• Are lateral-thinking approaches acceptable for this puzzle? Feb 22 '18 at 16:50
• No. But you can post it in comments I believe. btw The warden will execute them is they say a non-color word. Feb 22 '18 at 16:51
• Just have them all shout a color that is different from the two pre-determined colors ;) Feb 22 '18 at 16:52
• @LeppyR64 I mean, if they all choose a particular esoteric color, like "cerulean blue" the odds of them being exactly correct go down with the size of the color space. Even better if they pick a color with RGB values. The odds of them guessing the exact color approaches 0 as the color space gets larger. Feb 22 '18 at 20:34
• The real riddle is why all these wardens are offering to let prisoners go if they guess a hat color when they're convicted of crimes warranting execution. Feb 22 '18 at 23:33

This is a bit of a stretch and I'm not sure it'd even work, but...

Each prisoner should shout the one you see the least colors of.
If all colors the same, you shout the same color you see.

For convenience, I'll use black and white to represent the two possible different colors.
If the distribution is 2 whites and 2 blacks the prisoner sees 2 of one color and 1 of the other. The prisoner will always be right by this approach.
If the distribution is 3 whites and 1 black, the white ones will have all been wrong. If you're the 1 black in that scenario, you'll be wrong too.
Last but not least, if all are the same color, all will be right.

• I don't think the prisoners know in advance what the two potential colours are, so your prisoner could see three purple hats.
– c..
Feb 22 '18 at 20:20
• Yes, and that prisoner would say "purple". I used "black and white" to make the explaining easier, but it really works with any color presented by the warden. Feb 22 '18 at 20:22
• So simple and so effective! Feb 23 '18 at 1:19
• @HugoBDesigner I obviously did not spend enough time thinking about this, well done
– c..
Feb 23 '18 at 3:00
• @TonyEnnis The puzzle requires the prisoner to shout a color that exists in a hat. If there are two colors - say, black and white - but the prisoner can only see one of them, they're left at guesswork for the second color. Therefore, chances are they're shout a color that isn't in hats, thus failing the puzzle. Feb 24 '18 at 3:45

A simple way would be that

each prisoner guesses that there’s an even number of each colour.

Either there is, or there isn’t, but since everybody guessed the same, everyone will be right, or everybody will be wrong. No-one can be wrong by more than one, so whenever the guesses are a different number, the correct number is guaranteed to be the number in between.

EDIT: On closer inspection, this seems to be exactly what’s happening in @HugoBDesigner’s answer. Well, at least this explains why it works.

RE-EDIT: This approach turns out to be quite nice, since it generalises handily to N prisoners (decide in advance, which colour’s parity you are going to count), and it also points to the other solution:

Everybody can guess ”odd number of each colour”.
- if you see an odd number of ”white” hats, guess ”black”.
- if you see an even number of ”white” hats, guess ”white”.

(substitute the appropriate colours for the above technique.)

• Oh, that's much more elegant and it shows a connection with the answer to a similar puzzle. Feb 23 '18 at 1:52
• If a prisonner see three black, He cant know the second color. Your solution can work if you say the odd color. Not the even. Speaking if generalisation, i think it only works with an even number of hats. Feb 23 '18 at 6:39
• @Untitpoi I think you have that the wrong way around. If the prisoner sees three black hats and guesses there's an even number of each colour, the prisoner would say "black" without needing to know of any other colour. If the prisoner sees three black hats and guesses there's an odd number of each colour, that's when it won't work.
– hvd
Feb 23 '18 at 6:48
• @Untitpoi, if the warden insists that ”the colour that is not black” is not an adequate answer, and won’t tell the coulours in advance (and he might, totally erratic as he is), then there will be extra complications, and ”guess the odd colour” is the only working strategy.
– Bass
Feb 23 '18 at 7:14
• It looks like there may be a problem with odd N, if the warden at no point divulges the colours’ names.
– Bass
Feb 23 '18 at 11:58

My answer is similar to that of HugoB's but I think my reasoning adds something new to the solution. I was stuck turning it over and over in my head until I realised a key on how to start.

I start simply by realising that in the case of a 3-1 split happening, the person who sees three colours can only guess the colour he sees because he does not know what the second colour is.

Therefore,

to be assured of a certain escape, he must avoid any chance of failure (by chancing a non-existent colour) and he must guess the colour he sees.

Then,

you reason through what the other prisoners must say in order to match the "wrongness" or "rightness" of the person who only sees three and you come up with saying the lesser colour.

If, however,

there is a 2-2 case, the reasoning merely changes for the person who saw 3 same colours; he now sees two and guesses the lesser. If there is a 4-0 case, it is similar to the 3-1 because now everyone can only guess one colour because they only see one colour. Merely the "rightness" or "wrongness" changes.

All prisoners state

a colour that is indistinguishable on the human visible spectrum.

Examples of these colours can be red-green or blue-yellow, or (depending on the warden's definition of colour) ultra-violet or infra-red.

Due to the colours mentioned not being perceptible, the actual colour of their hats will appear to a human as a regular colour (the correct answer of their hats), ensuring that the prisoners are always giving a false answer, resulting in their freedom.

• A color is by definition visible. Feb 23 '18 at 3:33
• I like the answer... jpmc26, if we say a color must be visible, but it needn't be visible to a given observer. For instance if a fully color-blind person is looking at something, does it cease to have color? If a bee is looking at it but a human is too, does the bee stop perceiving that color? Feb 23 '18 at 9:07
• @SwissFrank Assuming red-green color-blindness (for example), red and green are both visible to the color-blind person. They just aren't distinguishable.
– Ray
Feb 23 '18 at 23:03

Assuming they are all either perfectly logical, or they were able to discuss a strategy before hand... The answer is;

They all say the color they see less of... Unless they don't see any of one color. Then they say the color they see. (if I see 3 whites I say white, if I see 3 blacks I say black.)

If it is an even 2-2 split;

Both whites see 2 blacks 1 white and say white, likewise black does the inverse.

if it is a 3-1 split;

Lets say that there are 1 white 3 blacks. White sees no white so they say black, each black sees 1 white and 2 blacks, they each say white, thus they are all wrong and win.

if it is a 4-0 split;

Lets say they are all white, they all see 3 whites and no black so they all say white. thus they are all right and win.

• How does your answer add to the identical one already given? You should always look at existing answers before providing one of your own, to ensure you are not just adding a duplicate.
– Rubio
Feb 22 '18 at 22:36
• when I answered this it was unclear if he had figured all of it out, because it hadn't been edited yet. Feb 23 '18 at 1:38

They all shout the same RGB hex-code, using 16 bits per channel, e.g. BBBB BBBB BBBB. The odds that they're all wrong is almost 100%. It's not exactly 100%, but it's certainly way closer than HugoBDesigner's answer. Of course you could use even more bits, but I'll just assume that at some point it won't matter to the warden, because the colors can't be distinguished by the human eye any further.

• If you can assign the colors based on real numbered RGB values (say between 0.0 and 1.0), the odds are actually 100% (i.e. they are "almost surely" correct. See: en.wikipedia.org/wiki/Almost_surely). Though in practice this might not work because I think light frequencies are quantized. Feb 23 '18 at 19:54
• The puzzle doesn't specify how the warden decides what color hats to use, so I don't think you can assume anything meaningful about probability. He could defeat this strategy by listening in on the prisoners' conversation and then using the color they agree to name. Feb 24 '18 at 14:55
• There are ways around people listening in and even ways around filming and such. They're thieves so they of all people would know about secret codes and whatnot. But note that the point is moot, because the OP has edited the question so that the thieves must all name one of the up to two colors that were used by the warden. So now the warden just distributes transparent hats and then kills them all. :-)
– Alex
Feb 27 '18 at 12:58

The funny thing is that while this puzzle seems not to offer enough info to solve at first glance, it's suprisingly amenable to

brute force.

If we merely make the observations that 1) it is symmetric and 2) the answer has to be based on how many hats of the majority color you see, then it boils down to:

1) what do you say if the majority is three hats?
2) what do you say if the majority is two hats?

(Choices of one and zero are eliminated by the definition of majority.)

And further... since you have to name an existing color, in question 1 you have to guess the majority color.

So the brute force analysis has only two cases to crank through--two possible answers for question 2--one of which clearly fails.

• This approach is roughly identical to Sam Harrington's answer, which itself is already a more complicated version of the accepted answer... Mar 1 '18 at 8:53
• The spoiler markup doesn't seem to be working on this answer and I have no idea why. Mar 1 '18 at 8:58
• @F1Krazy check my edit. You need to add extra spaces at the end of the line. It's kinda crazy but it does the job. Mar 1 '18 at 9:56