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.
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.
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.