Problem. On an island live perfect logicians; of them have blue eyes, the rest brown. Nobody knows their own eye colour, there are no mirrors and no talking about eyes; anyone who learns their own colour must leave at midnight, and everyone sees who left. One day a visitor announces publicly: “at least one of you has blue eyes”. What happens?

Answer. Nothing for nights; on night all blue-eyed islanders leave. (If everyone also knows that only blue and brown exist, the brown-eyed leave on night .) For the visitor told everyone something they already knew; what changed is that it became common knowledge.

Muddy children is the same puzzle: of children have mud on their foreheads, the father says “at least one of you is muddy” and asks repeatedly “do you know whether you are muddy?”; the muddy children answer “yes” in round .

NotionMeaningWith blue-eyed islanders before the announcement
”someone has blue eyes”true
(mutual knowledge)everyone knows true iff
everyone knows that everyone knows … ( times)true iff
(common knowledge) for every false; the announcement makes it true

The code below models knowledge explicitly with possible worlds (Kripke semantics): a world is a bitmask of eye colours, islander cannot distinguish from , and public events delete worlds.

// eyes[i] = 1 blue, 0 brown; only these two colours exist (common knowledge). After "someone is blue",
// every islander who knows their colour leaves that night; departures are public. Returns each one's night (0 = stays).
vector<int> leaveNights(const vector<int>& eyes) {
    int n = sz(eyes), W = 1 << n, actual = 0;
    for (int i = 0; i < n; i++) actual |= eyes[i] << i;
    vector<char> possible(W, 1); possible[0] = 0;             // the announcement deletes the all-brown world
    vector<vector<int>> hist(W);                              // public departure history if w were the real world
    vector<int> gone(W, 0), night(n, 0);
    for (int d = 1; d <= n + 1; d++) {
        vector<int> leave(W, 0);
        for (int w = 0; w < W; w++) if (possible[w])
            for (int i = 0; i < n; i++) if (!(gone[w] >> i & 1)) {
                int v = w ^ 1 << i;                           // the only world islander i cannot rule out by sight
                if (!possible[v] || hist[v] != hist[w]) leave[w] |= 1 << i;   // v is excluded: i knows
            }
        for (int w = 0; w < W; w++) if (possible[w]) hist[w].push_back(leave[w]), gone[w] |= leave[w];
        for (int i = 0; i < n; i++) if (leave[actual] >> i & 1) night[i] = d;
    }
    return night;
}