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

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.

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

]]>