1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include <vector>
#include <unordered_set>
#include <bitset>

using namespace std;

const int SIZE = 100;
using Screen = vector<bitset<SIZE>>;

// Funkcja do zmiany stanu pikseli
void changePixels(Screen& screen) {
    Screen newScreen = screen;
    for (int i = 0; i < SIZE - 1; ++i) {
        for (int j = 0; j < SIZE - 1; ++j) {
            bool a = screen[i][j];
            bool b = screen[i][j + 1];
            bool c = screen[i + 1][j];
            bool d = screen[i + 1][j + 1];
            if ((a == d && b == c && a != b) || (a == b && c == d && a != c)) {
                newScreen[i].flip(j);
                newScreen[i].flip(j + 1);
                newScreen[i + 1].flip(j);
                newScreen[i + 1].flip(j + 1);
            }
        }
    }
    screen = newScreen;
}

// Funkcja do generowania hasha dla ekranu
size_t hashScreen(const Screen& screen) {
    size_t hash = 0;
    for (const auto& row : screen) {
        hash ^= row.to_ullong() + 0x9e3779b9 + (hash << 6) + (hash >> 2);
    }
    return hash;
}

int main() {
    // Inicjalizacja ekranu jako szachownica
    Screen screen(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        for (int j = 0; j < SIZE; ++j) {
            screen[i][j] = (i + j) % 2;
        }
    }

    // Zbiór do przechowywania unikalnych konfiguracji (hashy)
    unordered_set<size_t> configurations;
    int seconds = 0;

    // Symulacja zmian ekranu
    while (true) {
        size_t hash = hashScreen(screen);
        if (configurations.find(hash) != configurations.end()) {
            break;  // Konfiguracja się powtórzyła
        }
        configurations.insert(hash);
        changePixels(screen);
        seconds++;
    }

    // Wypisanie początkowej konfiguracji
    for (const auto& row : screen) {
        for (int j = 0; j < SIZE; ++j) {
            cout << row[j];
        }
        cout << endl;
    }

    return 0;
}