From 6f080958ac1466c4597ef6a6eb6f91e8bb46e8a3 Mon Sep 17 00:00:00 2001 From: Andrew Ekstedt Date: Wed, 4 Dec 2024 06:22:21 +0000 Subject: [PATCH] day 4 part 2 --- day04/sol.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/day04/sol.c b/day04/sol.c index 93d2b3f..65b6326 100644 --- a/day04/sol.c +++ b/day04/sol.c @@ -109,10 +109,30 @@ int solve(struct grid *g) { 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() { struct grid g; - //readfile("sample2.in", &g); - readfile("input", &g); + readfile("sample2.in", &g); + //readfile("input", &g); printf("%d %d\n", g.x, g.y); solve(&g); + solve2(&g); }