--- /dev/null
+4134384626
+7114585257
+1582536488
+4865715538
+5733423513
+8532144181
+1288614583
+2248711141
+6415871681
+7881531438
--- /dev/null
+#include <stdio.h>
+
+void flash(char grid[10][10], int *flashes, int x, int y)
+{
+ //already flashed or not charged up enough
+ if (grid[y][x] == 0 || grid[y][x] < 10)
+ return;
+ (*flashes)++;
+ grid[y][x] = 0;
+ for (int dy = -1; dy<=1; dy++)
+ for (int dx = -1; dx<=1; dx++)
+ if ( (dx != 0 || dy != 0) &&
+ x+dx >= 0 && x+dx < 10 &&
+ y+dy >= 0 && y+dy < 10) {
+ if (grid[y+dy][x+dx] != 0)
+ grid[y+dy][x+dx]++;
+ flash(grid, flashes, x+dx, y+dy);
+ }
+}
+
+int main()
+{
+ int x = 0, y = 0;
+ int c;
+ char grid[10][10];
+ while( (c = getchar()) != EOF) {
+ if (c == '\n') {
+ y++;
+ x = 0;
+ } else {
+ grid[y][x++] = c-'0';
+ }
+ }
+
+ int flashes = 0;
+ for (int i = 0; i<100; i++) {
+ for (int y = 0; y<10; y++)
+ for (int x = 0; x<10; x++)
+ grid[y][x]++;
+ for (int y = 0; y<10; y++)
+ for (int x = 0; x<10; x++)
+ flash(grid, &flashes, x, y);
+ }
+
+ printf("%d\n", flashes);
+}
--- /dev/null
+#include <stdio.h>
+
+void flash(char grid[10][10], int *flashes, int x, int y)
+{
+ //already flashed or not charged up enough
+ if (grid[y][x] == 0 || grid[y][x] < 10)
+ return;
+ (*flashes)++;
+ grid[y][x] = 0;
+ for (int dy = -1; dy<=1; dy++)
+ for (int dx = -1; dx<=1; dx++)
+ if ( (dx != 0 || dy != 0) &&
+ x+dx >= 0 && x+dx < 10 &&
+ y+dy >= 0 && y+dy < 10) {
+ if (grid[y+dy][x+dx] != 0)
+ grid[y+dy][x+dx]++;
+ flash(grid, flashes, x+dx, y+dy);
+ }
+}
+
+int main()
+{
+ int x = 0, y = 0;
+ int c;
+ char grid[10][10];
+ while( (c = getchar()) != EOF) {
+ if (c == '\n') {
+ y++;
+ x = 0;
+ } else {
+ grid[y][x++] = c-'0';
+ }
+ }
+
+ int flashes = 0;
+ int gen = 0;
+ while (flashes != 100) {
+ flashes = 0;
+ gen++;
+ for (int y = 0; y<10; y++)
+ for (int x = 0; x<10; x++)
+ grid[y][x]++;
+ for (int y = 0; y<10; y++)
+ for (int x = 0; x<10; x++)
+ flash(grid, &flashes, x, y);
+ }
+ printf("%d\n", gen);
+}
--- /dev/null
+5483143223
+2745854711
+5264556173
+6141336146
+6357385478
+4167524645
+2176841721
+6882881134
+4846848554
+5283751526
CFLAGS:=-Wall -Wextra -O3
LFLAGS:=-f
-BINARIES:=$(foreach num,$(shell seq -f '%02.0f' 1 10),$(num)a $(num)b)
+BINARIES:=$(foreach num,$(shell seq -f '%02.0f' 1 11),$(num)a $(num)b)
all: $(BINARIES)