i would be

Just as in the 2-color hat, the person in the back has no way of knowing the color of their own hat. Their job is to give information to the people in front so that they can solve their own color.

The solution should work for any number of colors, but we'll do 3 as that was the riddle. Suppose we have red, green, and blue hats. In advance, they have time to work out a plan, and they assign a number from 1 to 3 to each one of those colors. For example, red is 1, green is 2, and blue is 3. Let's assume there are 6 people; I'll call them P1...P6, with P1 being in back, moving to P6 in front. P1 adds up the values of all the hats they see. For example, if they see RGBBG (their own is concealed), they would add 1+2+3+3+2=11. Then they do modulus 3 (sometimes the symbol % is used), which is just taking the remainder when the number is divided by 3. 11%3=2. (11/3 = 3 rem

**2**) P1 says "green," since 2 is green. (I suppose for

**0** they would say "blue," and is fine.) This may be correct or incorrect, the original problem said something to the effect that all but one had to be correct. P1 is the sacrifice. P2 sees GBBG or 2+3+3+2=10. P2 now knows that their hat is RED, because 1 is the only number between 1 and 3 that can be added to 10 to get

**2** when you mod it by 3. P2 says "red." P3 sees BBG or 3+3+2=8, and knows that their hat must be GREEN because if previous color is red, P2 must've seen values summing to 10, and 10-8=2=green. And so on.

I hope this is clear and doesn't give people a headache.