day 16 part 2 solved
[aoc_eblake.git] / 2016 / advent18.c
blob4a941d1efd788972a50c63a7226db94abf08dd4b
1 #define _GNU_SOURCE 1
2 #include <stdio.h>
3 #include <string.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include <stdbool.h>
8 #define MAX 100 // cheat by pre-inspecting input
10 int
11 main (int argc, char **argv)
13 int rows = 40;
14 if (argc > 1)
15 rows = atoi (argv[1]);
16 int safe = 0;
17 bool grid[2][MAX + 2] = { 0 }; // true for trap
18 int c;
19 int width = 0;
20 while ((c = getchar ()) != '\n') {
21 if (c == '^')
22 grid[0][width + 1] = true;
23 width++;
25 for (int i = 0; i < rows; i++)
26 for (int j = 1; j <= width; j++) {
27 if (!grid[i & 1][j])
28 safe++;
29 grid[!(i & 1)][j] = grid[i & 1][j - 1] ^ grid[i & 1][j + 1];
31 printf ("found %d safe tiles in %d rows\n", safe, rows);
32 return 0;