Once upon a time, there was a proud dwarf nation of 77777 citizens with pointy hats in all seven colors of the rainbow, and with a king who had a golden pointy hat. But to their great shame, they had lost all their pointy hats in a mine flooding. So they humbled themselves and went to the neighbouring country, the Land Where They Have Much Time, to ask for new hats. The king of that land listened to their plea, and then he said:
Good, you shall have new pointy hats. But your king will only get a golden pointy hat if he can prove that his people is diligent, smart and loyal to him. Therefore I give you the following task:
After each dwarf citizen has received his hat, in one of the seven colors, he must enter a room alone. In the room are seven wheels that are identically subdivided into seven colored sectors. The dwarf may then look at the wheels and turn them; they each click into place in one of seven possible positions, corresponding to the sectors. Then the dwarf exits the room and sits down on the Long Bench, on the leftmost free seat.
As soon as all dwarf citizens are sitting on the Long Bench, perhaps nothing happens or perhaps the hat of one dwarf is exchanged with a hat of a different color.
Afterwards, the dwarf king is allowed to inspect the seven wheels and the hats of his subjects, as they are sitting on the Long Bench, and he must tell me if a hat has been exchanged and if so, whose hat it was and what color it had before exchanging. Only if he can do that I will give him a golden hat!
The dwarfs accepted the offer, and since they revered their king, they deliberated intensely on how the riddle could be solved. Dwarfs being nerds, they soon found a solution. What might that solution have been?