Question : A bunch of people are living on an island, when a visitor comes with a strange order : all the blue-eyed people must leave the island as soon as possible. There will be a flight out at 8 PM every evening.Each person can see everyone else’s eye color, but they do not their own(nor is anyone allowed to tell them). Additionally they do not know how many people have blue eyes, although they do know that at least one person does. How many days will it take to blue-eyed people to leave?
Solution: Assume that there are n people on the island and c of them have blue eyes. We are explicitly told that c > 0.
Case c = 1: Exactly one person has blue eyes
The blue-eyed person should look around and realize that no one else has blue eyes. Since, he knows that at least one person has blue eyes, he must conclude that it is he who has blue eyes. Therefore he would take the flight that evening.
Case c = 2: Exactly two person has blue eyes
The two blue-eyed people see each other, but are unsure whether c is 1 or 2. They know from the previous case that if c = 1, the blue eyed-person would leave on the first night. Therefore, if the other blue-eyed person is still there, he must deduce that c=2 which means he himself has blue eyes. Both men would then leave on the second night.
Case c > 2: The general case
As we increase c, we can see that this logic continues to apply. If c=3, then those three people will immediately know that there are either 2 or 3 people with blue eyes. If there were two people, then those two people would have left on the second night.So, when the others are still around after that night, each person would conclude that c=3 and that they, therefore, have blue eyes too. They would leave that night.
This same pattern extends up through any value of c. Therefore, if c men have blue eyes, it will take c nights for the blue-eyed men to leave. All will leave on the same night.
This article is contributed by Brahmani Sai. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.