TITLE: Rainbow Hats Puzzle
QUESTION [21 upvotes]: Seven prisoners are given the chance to be set free tomorrow. An
  executioner will put a hat on each prisoner's head. Each hat can be
  one of the seven colors of the rainbow and the hat colors are assigned
  completely at the executioner's discretion. Every prisoner can see the
  hat colors of the other six prisoners, but not his own. They cannot
  communicate with others in any form, or else they are immediately
  executed. Then each prisoner writes down his guess of his own hat
  color. If at least one prisoner correctly guesses the color of his
  hat, they all will be set free immediately; otherwise they will be
  executed. They are given the night to come up with a strategy. Is
  there a strategy that they can guarantee that they will be set free?

So I came across a puzzle today that even after reading the explanation of the solution I do not understand how it mathematically works. I think it's a pretty interesting question so I won't post the answer (I probably can't phrase it right anyways considering I don't understand it). It might be a common math puzzle anyways. 
I was hoping someone could give me an intuitive and mathematical explanation as to how to solve this and why it works. Is it also possible to give the step by step thought process of constructing this solution?

REPLY [2 votes]: Here's how I think of it: like other answers, assume the hats are numbered 0 to 6 (instead of colors).  If any player knew the sum of all hats mod 7 (including his own) it would be trivial to deduce his hat color.  The problem, of course, is that no one knows the sum.
So the strategy is simply to go around the room and say to each player, "You answer assuming the sum is 0", then "You answer assuming the sum is 1", and so forth.  The sum has to be between 0 and 6, so someone will get it right.