advent2025

Advent of Code 2025 Solutions
git clone git://bsandro.tech/advent2025
Log | Files | Refs | LICENSE

commit afb256e15a18d1ae501cfb9162adfdea1b8c584e
parent b882276f2387d250e46e6d88919c513aaf3bcbf3
Author: bsandro <email@bsandro.tech>
Date:   Thu,  4 Dec 2025 20:14:06 +0200

day04 optimization that actually made thing slower (but added more sanity as far as cellular automata goes

Diffstat:
Mday04.c | 11+++++------
1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/day04.c b/day04.c @@ -1,4 +1,5 @@ #include <stdio.h> +#include <string.h> #include "cputime.h" // +1 on all sides @@ -26,10 +27,12 @@ int count_adj(Map map, int x, int y) { } int clean(Map map) { + Map map1; + memcpy(map1, map, sizeof(Map)); int rem = 0; for (int y=1;y<H-1;++y) { for (int x=1;x<W-1;++x) { - if (map[y][x]=='@'&&count_adj(map, x, y)<4) { + if (map1[y][x]=='@'&&count_adj(map1, x, y)<4) { map[y][x]='.'; rem++; } @@ -52,15 +55,11 @@ int main(void) { } int p1 = 0; - for (int y=1;y<H-1;++y) { - for (int x=1;x<W-1;++x) { - if (map[y][x]=='@'&&count_adj(map, x, y)<4) p1++; - } - } int p2 = 0; while (1) { int rem = clean(map); p2 += rem; + if (p1==0) p1 = rem; if (rem==0) break; } printf("p1: %d\np2: %d\n", p1, p2);