Blue Eyes On An Island

An island has 1,000,000 inhabitants. Each inhabitant has blue eyes or brown eyes. There are no reflective surfaces on the island, so no inhabitant knows their own eye color. The custom of the island also prevents anyone from talking or communicating about eye colors. The inhabitants are otherwise completely logical, able to deduce everything that can be deduced in an hour or so. If anyone knows their eye color, they must leave the island at the next midnight, never to return. All inhabitants know this paragraph.

An outsider that wants to wreck havoc arrives at the island and declares that there are a composite number of inhabitants who have blue eyes, before promptly fleeing. What is the minimum possible number of midnights after which the island gets completely deserted, no matter how many inhabitants with blue eyes there were initially?


The answer is 57.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Ivan Koswara
Jan 8, 2017

This is not written formally yet; I skip a lot of details to present mostly the main idea.

Yes, this is a variant of the well-known blue-eyed islander puzzle. The usual question is that the statement by the outsider is "there is a blue-eyed islander", and this variant is "there is a composite number of blue-eyed islanders". (I hope I didn't botch up the first paragraph, because it's very crucial to the puzzle, but I hope that if you already know the problem, you can take from it.)

First, you need to prove yourself that whatever nontrivial statement it is (a trivial statement is true for all numbers of blue-eyed islanders; a nontrivial statement is false for some number), the island will eventually get deserted. The proof is by induction, as usual. Or you can read the proof here .

If you also know how the proof goes, the induction step works as follows. If n n is the actual number of blue-eyed islanders, and m m is the closest number to n n where the statement is false if there are m m blue-eyed islanders, then:

  • n = m n = m can't happen, because then the outsider is lying.
  • if n > m n > m , then after the ( n m ) (n-m) -th midnight, the blue-eyed islanders leave. If there are any brown-eyed islanders left, they leave on the next midnight.
  • if n < m n < m , then after the ( m n ) (m-n) -th midnight, the brown-eyed islanders leave. If there are any blue-eyed islanders left, they leave on the next midnight.
  • if n n is equally close to two such forbidden numbers, all islanders leave on the same midnight.

Finally, it's just the task of finding the smallest k k such that all islanders will leave by the k k -th midnight, no matter what n n was initially. Since the forbidden numbers are the prime numbers (and 0 and 1), this is equivalent to finding the largest gap between two prime numbers; our n n will be precisely in the middle between these two prime numbers. (There is an additional complication near the edges; for example, with n = 1000000 n = 1000000 , m m cannot be larger, so it will be eliminated by the case n > m n > m only. As it turns out, this one doesn't matter; m = 999983 m = 999983 , so n = 1000000 n = 1000000 is eliminated by the 18th midnight.)

This is a simple task to program. Simply sieve the prime numbers up to 1000000 and find the largest gap. This occurs between 492113 and 492227, with a gap of 114; at n = 492170 n = 492170 , the last case will occur after 57 midnights, and this is our answer.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
def eratosthenes2(n):
    multiples = set()
    for i in range(2, n+1):
        if i not in multiples:
            yield i
            multiples.update(range(i*i, n+1, i))

l = list(eratosthenes2(1000000))
m = 0
for i, j in zip(range(len(l)),range(1,len(l)-1)):
    if l[j] - l[i] > m:
        m = l[j] - l[i]

print("Max Gap: ")
print(m)

How do you choose which of "blue-eyes" white dragon (wait, jk, person hahaha) that will leave?

Muhammad Reza - 4 years, 5 months ago

Log in to reply

All blue-eyed islanders will leave on the same midnight; the situation is symmetrical from their viewpoint.

Ivan Koswara - 4 years, 5 months ago

what about this case? one brown eye and 99999 blue eyes. This will require only two midnights. The question: After how many midnights at l e a s t least does the island get completely deserted

Ossama Ismail - 4 years, 5 months ago

Log in to reply

The question is "after how many midnights at least does the island get completely deserted, no matter how many blue-eyed inhabitants there were ". If there are 8 blue-eyed islanders, it's true that it takes only two midnights; but what happens in other cases? Are two midnights enough for other cases? (999999 blue-eyed islanders takes 17 midnights. If you meant 1 blue-eyed islander, that makes the outsider to lie, not permitted.)

Ivan Koswara - 4 years, 5 months ago

Log in to reply

I misled by the word "at least" ???

Ossama Ismail - 4 years, 5 months ago

Log in to reply

@Ossama Ismail Yes, the words "at least" needs to be there; otherwise you just say "1000000 midnights".

Ivan Koswara - 4 years, 5 months ago

If you interpreted it that way, then the min is 1. Let's say there's 4 blue.

Each blue sees 3 others, so concludes that s/he's the fourth. They leave night 1.

Each brown sees 4 blue, so concludes that s/he could not be the fifth. They also leave night 1.

Zach Bian - 4 years, 5 months ago

What does happen if we have only one brown eyes and 999999 blue eyes?

Abdelhamid Saadi - 4 years, 4 months ago

Log in to reply

After 16 midnights, the blue-eyed islanders can conclude they are blue-eyed and leave the island. The next midnight, the lone islander knows they have brown eyes and also leave the island.

Ivan Koswara - 4 years, 4 months ago

Log in to reply

I am trying to look to limit conditions.

The brown eye may leave the first night, thinking he's the only brown eye in the island. or Would he already left a long time ago?

Abdelhamid Saadi - 4 years, 4 months ago

Log in to reply

@Abdelhamid Saadi Before that statement, nobody can figure out their eye color yet. The brown-eyed islander doesn't know whether they have the sole brown eyes, or that everyone on the island including them have blue eyes.

After that statement, the brown-eyed islander still doesn't know it. (A statement that would make them to know immediately is something that says there's at least one brown-eyed islander; the statement doesn't rule out the possibility that there is no brown-eyed islander, so they don't know.)

Ivan Koswara - 4 years, 4 months ago

What would be the result if the inhabitants number is 10,000?

Abdelhamid Saadi - 4 years, 4 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...