I'm not sure this will even work, let's say there are 86 red hats and 14 green. The devil will put 14 green hats in a random order so it could be the fourth person gets a green hat then the 48th then 57 then 68 and so on. So the first person will count an even number of red hat's he'll say green but there's no way of knowing for sure, same with the guy thats second he'll say green when it will be red and the third guy will say red which will be right but i don't think this saves 100/100 or 99/100 whichever one you said
Okay: First of all, the red=odd, green= even rule only applies to the first person. Everyone else uses what the first person said and logic to figure out their own hat color. What do you mean "there is no way of knowing for sure?" It can be assumed that everyone in line knows how to count, and will not make stupid counting mistakes. Now, the exact
number of red hats doesn't really matter anyway. Just whether they are odd or even.
So, in you example, the first three people are wearing red hats, right? Then, first of all, the first guy would say RED, not green. This is because he is not able to see is own hat, and would see 85 (an odd number) of red hats.
Then, the second guy would say RED as well, why? Because he sees 84 red hats (86 red- his own- the first guys= 84). But, he knows that the first guy saw an odd number of hats, be he sees an even number. This only makes sense if there is a red hat that the first person can see that the second person cannot see. The only hat that fits this description is, of course, the hat that the second guy is wearing.
Now, the third guy sees 83 red hats, right? But, he ALSO knows that the second guy said "red". So, he knows, not including his own, that there are at least 84 red hats. Yet, he knows that the very first person saw an odd number of red hats. So, using the same logic as before, he MUST have a red hat.
Okay, Fourth guy: He sees 83 red hats as well. But, he also knows that the first two guys said red, making it 85 red hats total. He knows that the first guy also saw an odd number of red hats. So, lets think about it:
1) If he was wearing a red hat, than the first guy would have saw 86 red hats, but that's an even number.
2) So, he must be wearing a green hat, by default.
And so on.
So, a few things you have to keep in mind:
1) Everyone knows that the first person can see everyone's (not including the first person, who doesn't really count since we know we cannot save him) hat. They know that he has the most complete knowledge about the other 99 people in line.
2) Everyone knows the color of the hat of the other 98 people in line. Therefore, there is only one hat (their own) that differs from what the first guy said.
3) If what they can see/hear agrees with the first guy, then they must have a green hat. If it disagrees, then it must disagree because their own hat is red. Think about it: the ONLY way the first guy could see an odd number of red hats among the 99 people, but someone in the line to know that among the other 98 people there is an even number of red hats, is if his own hat is the "missing" red hat. This is by virtue of the fact that any even number +1 is an odd number.