advent2025

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

commit 164d5e2fa652b528c8f0de1b41f4520a80bf620b
parent 9e218d4783dc432e405a84c993f919178022bbe2
Author: bsandro <email@bsandro.tech>
Date:   Thu, 11 Dec 2025 22:39:43 +0200

day11 p2 still does not work but I feel I am close

Diffstat:
MMakefile | 3+++
Mday11.c | 46++++++++++++++++++++++++++--------------------
2 files changed, 29 insertions(+), 20 deletions(-)

diff --git a/Makefile b/Makefile @@ -36,6 +36,9 @@ endif %+test: %.bin ./$< < inputs/$*_test.txt +%+test1: %.bin + ./$< < inputs/$*_test1.txt + .SECONDARY: %: %.bin @: diff --git a/day11.c b/day11.c @@ -1,3 +1,9 @@ +/* +Test input #1 works only with part1 of the puzzle. +Test input #2 works only with part2 of the puzzle. +Thing crashes pretty hard if 'svr'/'our' nodes weren't found, I don't care much. + */ + #include <stdio.h> #include <string.h> #include <strings.h> @@ -6,13 +12,14 @@ #include "cputime.h" #define NAME_LEN 4 -#define MAX_NODES 100000 +#define MAX_NODES 10000 typedef struct Node { char name[NAME_LEN]; int adj_l; int adj[32]; bool visited; + bool dead; } Node; typedef struct { @@ -60,12 +67,14 @@ int find_or_create(Nodes *nodes, char name[4]) { int bfs(Nodes *nodes) { int num = 0; int start = find_index(nodes, "you"); + if (start==-1) return -1; int end = find_index(nodes, "out"); int queue[MAX_NODES] = {0}; int front = 0; int back = 0; queue[back++] = start; while (front<back) { + if (front>=MAX_NODES||back>=MAX_NODES) exit(1); int cur = queue[front++]; if (cur==end) num++; Node *cur_node = &nodes->nodes[cur]; @@ -76,44 +85,40 @@ int bfs(Nodes *nodes) { return num; } -int dfs_walk(Nodes *nodes, int idx) { - int end = find_index(nodes, "out"); - int dac = find_index(nodes, "dac"); - int fft = find_index(nodes, "fft"); - if (idx==end) { +int dfs_walk(Nodes *nodes, int idx, int out, int dac, int fft) { + if (idx==out) { + for (int i=0;i<nodes->cnt;++i) if (nodes->nodes[i].visited) printf("-> %3d ",i); + printf("\n"); if (nodes->nodes[dac].visited&&nodes->nodes[fft].visited) return 1; else return 0; } Node *n = &nodes->nodes[idx]; n->visited = true; + if (n->dead) return 0; int num = 0; for (int i=0;i<n->adj_l;++i) { - num += dfs_walk(nodes, 0); + if (nodes->nodes[n->adj[i]].visited) continue; + //if (nodes->nodes[n->adj[i]].dead) continue; + num += dfs_walk(nodes, n->adj[i], out, dac, fft); } n->visited = false; + if (num==0) n->dead = true; return num; } int dfs(Nodes *nodes) { int num = 0; + int out = find_index(nodes, "out"); + int dac = find_index(nodes, "dac"); + int fft = find_index(nodes, "fft"); Node *start = find(nodes, "svr"); + if (start==NULL) return -1; for (int i=0;i<start->adj_l;++i) { - num += dfs_walk(nodes, start->adj[i]); + num += dfs_walk(nodes, start->adj[i], out, dac, fft); } return num; } -void print_nodes(Nodes *nodes) { - printf("%d nodes\n", nodes->cnt); - for (int i=0;i<nodes->cnt;++i) { - printf("(%d) [%s] -> ", i, nodes->nodes[i].name); - for (int j=0;j<nodes->nodes[i].adj_l;++j) { - printf("[%d:%s]", nodes->nodes[i].adj[j], nodes->nodes[nodes->nodes[i].adj[j]].name); - } - printf("\n"); - } -} - int main(void) { char buf[NAME_LEN]; int buf_l = 0; @@ -133,7 +138,8 @@ int main(void) { } int p1 = bfs(nodes); - int p2 = 0;//dfs(nodes); + int p2 = dfs(nodes); printf("p1: %d\np2: %d\n", p1, p2); return 0; } +// 18