## A Hat Trick

My readers know that I love hat puzzles. This is why I decided to turn a number trick by Konstantin Knop (in Russian) into a hat trick.

Hat Trick.The audience has a bottomless supply of hats in ten different colors. They arrange ten people in a line and put one of the hats on each person. Then the magician’s assistant comes in and removes a hat from one of the ten people. After that, the magician appears and, abracadabra, guesses the color of the removed hat. The magician and the assistant agreed on a strategy beforehand. What is it?

Keep in mind that this trick won’t work with fewer than ten colors. As a bonus, can you explain why?

*Sep 18, 2022 Correction: I meant “with fewer than ten people.”*

## Tanya Khovanova's Math Blog » Blog Archive » A Hat Trick - New Marathi Live:

[…] Source link […]

17 September 2022, 12:29 pm## Leo:

Hi,

This one is very nice, thank you!

If the people are ordered (0-9) and the colors have codes (0-9). Then the assistant can

Compute the sum of the hats mod 10 and remove the hat for the corresponding person

The magician then knows what the mod-10 sum of the hats must have been and can guess the missing color.

Probably I am missing something here, because this works as long as there sre as many colors as people.

(In particular by ignoring some people in the line it works if there are less colors than people)

From an information point of view, the assistant has “number of people” choices to signal “number of colors” information. So if we have less people than colors it should not work..

18 September 2022, 3:49 am## James:

It seems to work ok with two colours! If hats 9 and 10 are the same colour, remove hat 9. If hats 9 and 10 are different colours, remove hat 10.

18 September 2022, 8:39 am## Zarunias:

This reminds me of a card trick: From a standard card deck (52 cards) the assistant is given 5 random cards. The assistant now reveals 4 of the cards one after another. Then, the magician guesses the suit and value of the remaining card. Of course also in this trick the magician and the assistant agreed on a strategy beforehand. I love this trick especially from the mathematical point of view – the number of suits and the number of cards per suits are just too perfect for this trick.

18 September 2022, 10:07 am## Carl Feynman:

They agree on a code mapping the hats one-to-one to the numbers 0..9. The assistant computes the sum of the hats modulo 10, and removes the hat from that person, numbering the people as 0..9. The magician solves the modular equation.

I don’t see why this restricted to ten types of hat, as long as the number of hat types is less than or equal to the number of people.

18 September 2022, 12:50 pm## Puzzled:

Let the colors be 0, … , 9 and so be the positions of the 10 people in the line. The assistant calculates the sum of all the hat numbers he sees, takes it mod 10 and removes the hat of the person with that number. The magician immediately knows the sum of 10 numbers by the missing hat position and calculates the sum of 9 visible hats. So the difference mod 10 is the number he announces.

18 September 2022, 12:50 pmThis clearly works with n colors and m people in the line if m>=n. In case n<m the magician can encounter m*n^{m-1} hat combinations. The number of initial combinations he can recreate is no larger. But there are n^m possible initial combinations.

## Bruce:

Zarunias: same here. For more on (Fitch Cheney’s) card trick, there is an article Kleber, M., The Best Card Trick. Mathematical Intelligencer, 24 (2002), and a discussion on the probably wrong blog (https://possiblywrong.wordpress.com/2011/05/29/generalizing-fitch-cheneys-five-card-trick/).

8 October 2022, 3:58 pmIn both cases, the assistant has enough choices to signal a 1 of N choice, but they are not told specifically what hat or card to signal.

It takes a satisfying aha moment to figure out how to make the hidden hat/card agree with the signal being sent.