Sorting hats


A group of prisoners are offered a chance of freedom. The prisoners will be brought in one at a time, and a black or white hat will be placed on their heads as they come in.

The prisoners must form a line with white hats on one side and black hats on the other. The prisoners can’t communicate, and can only choose their position in the line.

How can the prisoners succeed?

As each prisoner enters, they simply join the line at the point between an adjacent black and white hat. If there are only hats of one color they can join at either end of the line.

This always preserves the property that the line is always valid at all times. Note, that the prisoners don’t need to communicate beforehand.