Hundred most brilliant logicians are handpicked from the world and invited to a room. But before they could enter, they are told that at least one of them has a black forehead. Whenever anyone can frame out that he is having a black forehead, he needs to leave the room when the lights are turned off. After that, the lights are turned back on and those who could infer that their forehead was black have left the room.
What happens if they have painted every forehead black?
Solution:
Since there are 100 logicians, the lights are turned on and off hundred times and after the 100th time, all the logicians leave the room.
If all of them sees 99 black foreheads, the lights get turned off. When the light is turned on again, everyone is able to see 99 black foreheads again. This happens 100 times and then every logician leaves the room.
Let us make it more simplified for you. Assume that only one person has a black forehead. The people who invited them said that at least one person has a black forehead and as they turn off the lights, that logician leaves.
Imagine the scenario with two logicians having black forehead. One of the logician sitting there must be thinking "I have a black forehead or I don't have a black forehead. If I am not the one with black forehead, the other logician with black forehead will deduce that he is having a black forehead and then he will leave."
"If I don't have a black forehead, the other logician will stay and thus I must be having a black forehead as well. Thus we must leave when the lights are turned off for the second time"
When you repeat the logic to 100 times, you will get the answer.