easters

easters.dev solutions (C)
git clone git://bsandro.tech/easters
Log | Files | Refs | LICENSE

commit 162f10f814e0c4dbd6e87af11f32336864953fc6
parent 5c2bd8c9060975d23627e7152cb4f7889a9be2d9
Author: bsandro <email@bsandro.tech>
Date:   Mon, 12 Jan 2026 21:03:53 +0200

Part 2

Diffstat:
Msunday.c | 31+++++++++++++++++++------------
1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/sunday.c b/sunday.c @@ -82,17 +82,17 @@ void printMap(Map *m) { } } -bool validateMap(Map *m) { +bool validateMap(Map *m, int mul) { bool ok = true; for (int x=0;x<m->w;++x) { - if (countMinesX(m, x)!=m->xmines[x]) { + if (countMinesX(m, x)!=m->xmines[x]*mul) { ok = false; break; } } if (!ok) return false; for (int y=0;y<m->h;++y) { - if (countMinesY(m, y)!=m->ymines[y]) { + if (countMinesY(m, y)!=m->ymines[y]*mul) { ok = false; break; } @@ -112,15 +112,15 @@ int calcChecksum(Map *m) { return r; } -int findMines(Map *m, Vec2 *nodules, int nodules_s) { - if (nodules_s==0&&validateMap(m)) { +int findMines(Map *m, Vec2 *nodules, int nodules_s, int mul) { + if (nodules_s==0&&validateMap(m, mul)) { return calcChecksum(m); } ArVec2 mines = findPossibleMines(m, nodules[0]); for (int i=0;i<mines.len;++i) { Map m1 = *m; m1.grid[mines.data[i].y][mines.data[i].x] = 'M'; - int csum = findMines(&m1, nodules+1, nodules_s-1); + int csum = findMines(&m1, nodules+1, nodules_s-1, mul); if (csum!=0) return csum; } return 0; @@ -128,8 +128,6 @@ int findMines(Map *m, Vec2 *nodules, int nodules_s) { int main(void) { Map map = {0}; - Vec2 nodules[50] = {0}; - int nodules_s = 0; for (char c=getchar();c!=EOF;c=getchar()) { if (c>='0'&&c<='9') { if (map.h==0) { @@ -145,15 +143,24 @@ int main(void) { } } map.h-=1; + Vec2 nodules1[32] = {0}; + Vec2 nodules2[32] = {0}; + int nodules1_s = 0; + int nodules2_s = 0; for (int y=0;y<map.h;++y) { for (int x=0;x<map.w;++x) { - if (map.grid[y][x]=='O') { - nodules[nodules_s++] = (Vec2){ .x=x,.y=y }; + char c = map.grid[y][x]; + if (c=='O') { + nodules1[nodules1_s++] = (Vec2){ .x=x,.y=y }; + nodules2[nodules2_s++] = (Vec2){ .x=x,.y=y }; + } + if (c=='G') { + nodules2[nodules2_s++] = (Vec2){ .x=x,.y=y }; } } } - int cs = findMines(&map, nodules, nodules_s); - printf("part 1: %d\n", cs); + printf("part 1: %d\n", findMines(&map, nodules1, nodules1_s, 1)); + printf("part 2: %d\n", findMines(&map, nodules2, nodules2_s, 2)); return 0; }