A classic maths puzzle involves a line of one hundred prisoners, who have each been given a black or white hat by their nefarious captor, and must each correctly shout out the colour of their hat to win freedom. The twist is that the prisoners don’t know the colour of their own hat, and though they can see the colours of the hats in front of them, they don’t know many of each colour there are overall. They can confer on a strategy beforehand, and the aim is to get as many of them to correctly identify their hat colour as possible. You can find a full explanation here (and in many other places!)

There are several ‘sequels’ to this puzzle, some involving an infinite number of prisoners and requiring the axiom of choice to solve. This post is about a nice variation on the theme that I heard about at a recent MathsJam. It can (just about) be solved without knowledge of higher mathematics, and though it seems impossible at first glance, the prisoners in this situation can in fact save themselves with 100% certainty.