The mind reader who survives a lie

Think of a number from 0 to 15 and keep it secret. For each of the seven cards, say whether your number is on it. You may lie on one card if you like. The page will name your number anyway, and tell you which answer was the lie. Then switch to Reveal to see how.

Answer all seven cards, then click Read my mind.

What's going on

Cards 3, 5, 6 and 7 are the ordinary binary cards for 8, 4, 2 and 1. Cards 1, 2 and 4 are checking cards, chosen so that three groups of answers always contain an even number of yeses: cards 1, 3, 5, 7; cards 2, 3, 6, 7; and cards 4, 5, 6, 7. Those groups are the cards whose numbers have a 1 in the ones place, the twos place and the fours place.

A lie on card k breaks exactly the checks that card k belongs to, and those checks are the binary digits of k. Score 1, 2 and 4 for the failed checks and the total names the liar. Flip it back and read the number off cards 3, 5, 6, 7. If nothing fails, nobody lied.

This is the Hamming(7,4) code: four bits of message, three bits of checking, any single error corrected. The 16 honest strings, each with its 7 one-lie neighbours, account for 16 × 8 = 128 = 27 strings: every seven-bit string belongs to exactly one secret. That perfect fit is why two lies send the decoder confidently to the wrong answer, which the Two lies tab lets you watch.

Sheet: The mind reader who survives a lie. Related: Counting to 31 on one hand, Odd, even and things that never change.