10 #define MAX 3000 // guessing that 10000 iterations won't grow that large
26 static enum state grid
[MAX
][MAX
];
29 main (int argc
, char **argv
)
31 int cycles
= 10000000;
33 cycles
= atoi (argv
[1]);
40 while ((nread
= getline(&line
, &len
, stdin
)) >= 0) {
42 assert ((nread
& 1) == 0);
44 x
= y
= MAX
/ 2 - nread
/ 2;
45 printf ("populating starting at %d,%d\n", x
, y
);
59 printf ("parsed %dx%d inputs, starting at %d,%d\n", count
, count
, x
, y
);
61 for (int i
= 0; i
< cycles
; i
++) {
77 infected
+= (grid
[y
][x
] = (grid
[y
][x
] + 1) % 4) == I
;
94 if (!x
|| !y
|| x
== MAX
- 1 || y
== MAX
- 1) {
95 printf ("grid is too small at iteration %d\n", i
);
99 printf ("after %d cycles, infected %d nodes\n", cycles
, infected
);