The puzzle that I am posting here has already been answered by "Set Big O" on the following link https://puzzling.stackexchange.com/questions/11744/alternating-hat-colors
I understood his method but couldn't understand how he came up with the method or why his method gives the correct solution. Please help me in understanding why his method works.
Here is the puzzle :
"A prison warden offers his inmates a game for their freedom. He will secretly write a number on each of their foreheads, with no two foreheads having the same number. The inmates get to look around, seeing every other inmates' forehead, but not their own. They then go into separate rooms, and each place either a white or black hat on their own head. When they return, the prisoners are lined up in order of forehead number. They win if their hat colors now alternate white/black.
Once the game begins, the prisoners may not communicate, but beforehand, they may agree on a strategy. How can they guarantee victory?
This puzzle has a logical solution, there is no need for lateral thinking.
Added remarks: The numbers aren't necessarily integers, or positive, or interrelated at all (except they are all different). The numbers are the wardens choices, while the hat colors are the prisoners' choice. I got this from Rustan Leino's puzzle page."