day 4 part 2
parent
5cb39af7b8
commit
6012f7757c
20
day04/sol.c
20
day04/sol.c
|
@ -109,10 +109,30 @@ int solve(struct grid *g) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int solve2(struct grid *g) {
|
||||||
|
int x, y;
|
||||||
|
int count = 0;
|
||||||
|
const char *word = "MAS";
|
||||||
|
for (y = 0; y < g->y; y++)
|
||||||
|
for (x = 0; x < g->x; x++) {
|
||||||
|
if (g->A[y][x] != 'A') continue;
|
||||||
|
int mas = 0;
|
||||||
|
if (search(g, x-1, y-1, +1, +1, word)) { mas++; }
|
||||||
|
if (search(g, x+1, y+1, -1, -1, word)) { mas++; }
|
||||||
|
if (search(g, x-1, y+1, +1, -1, word)) { mas++; }
|
||||||
|
if (search(g, x+1, y-1, -1, +1, word)) { mas++; }
|
||||||
|
if (mas == 2) { count++; }
|
||||||
|
}
|
||||||
|
printf("%d\n", count);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
struct grid g;
|
struct grid g;
|
||||||
//readfile("sample2.in", &g);
|
//readfile("sample2.in", &g);
|
||||||
readfile("input", &g);
|
readfile("input", &g);
|
||||||
printf("%d %d\n", g.x, g.y);
|
printf("%d %d\n", g.x, g.y);
|
||||||
solve(&g);
|
solve(&g);
|
||||||
|
solve2(&g);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue