--- Day 11: Octopodes ---

December 11

Listening to: Relaxing N64 music


Octopodes. Octopi? Octopuses? The appendagey sea creacures.

Anyway, they get flashy. This one looks kinda fun!

void flash(int x, int y) {
    if (board[x][y] <= 9) return;

    flashes++;
    board[x][y] = 0;
    for (int i = max(x-1, 0); i <= min(x+1, 9); i++)
    for (int j = max(y-1, 0); j <= min(y+1, 9); j++)
        // 0 = just flashed; don't re-flash
        if (board[i][j] != 0)
            // If threshold met, recursively flash
            if (++board[i][j] > 9)
                flash(i, j);
}
for (int i = 0; i < DAYS; i++) {
    // Step 1: increase energy
    for (int x = 0; x < 10; x++)
    for (int y = 0; y < 10; y++)
        board[x][y]++;

    // Step 2: flash area
    for (int x = 0; x < 10; x++)
    for (int y = 0; y < 10; y++)
        flash(x, y);
        
    // Counter
    cout << "Day\t" << i+1 << ": " << flashes << endl;
}

I kept getting the recursive loop wrong, particularly when trying to target adjacent squares. It took a bit. But it works!


Figured they would do something with syncing up, since it seems like they would start to. At the very least, it's an easy modification to the solution!

// step 3: Check for full syncronicity
int octoSum = 0;
for (int x = 0; x < WIDTH; x++)
for (int y = 0; y < WIDTH; y++)
    octoSum += board[x][y];

if (octoSum == 0) break;

And now all of the octopodes are friends

🐙🐙🐙 🐙🐙🐙 🐙🐙🐙


My solutions for today's puzzles