advent2025

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

commit 696c97dfbc0044eae886826da74fb6176b3364e0
parent 6b2100de96447358c00d365e5448dac30fcb5686
Author: bsandro <email@bsandro.tech>
Date:   Tue,  9 Dec 2025 00:32:22 +0200

day08 "cleanup"

Diffstat:
Mday08.c | 25+++++--------------------
1 file changed, 5 insertions(+), 20 deletions(-)

diff --git a/day08.c b/day08.c @@ -100,14 +100,6 @@ static int cmp_circuits(const void *vc1, const void *vc2) { return c2->points_l - c1->points_l; } -void points_print(int points_l, Point *points[points_l]) { - for (int i=0;i<points_l;++i) { - Point *p = points[i]; - printf("[%d]", p->x); - } - printf("\n"); -} - static int circuits_merge(int circuits_l, Circuit *circuits) { int new_len = circuits_l; for (int i=0;i<circuits_l;++i) { @@ -167,32 +159,25 @@ int main(void) { int circuits_l = 0; for (int i=0;i<CONNS;++i) { circuits_add(&circuits_l, circuits, &dists[i]); - } - int len_prev = circuits_l; - while (1) { circuits_l = circuits_merge(circuits_l, circuits); - if (circuits_l==len_prev) break; - len_prev = circuits_l; } qsort(circuits, circuits_l, sizeof(Circuit), cmp_circuits); part1 = circuits[0].points_l*circuits[1].points_l*circuits[2].points_l; - // ------------------------------------ free(circuits); + // ------------------------------------ circuits = calloc(dists_l, sizeof(Circuit)); circuits_l = 0; for (int i=0;i<dists_l;++i) { circuits_add(&circuits_l, circuits, &dists[i]); - int len_prev = circuits_l; - while (1) { - circuits_l = circuits_merge(circuits_l, circuits); - if (circuits_l==len_prev) break; - else len_prev = circuits_l; - } + circuits_l = circuits_merge(circuits_l, circuits); if (circuits[0].points_l==points_l) { part2 = dists[i].p1->x * dists[i].p2->x; break; } } + free(circuits); + free(dists); + free(points); printf("p1: %"PRIu64"\np2: %"PRIu64"\n", part1, part2); return 0;