advent2025

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

commit f2bcf7b53dda11fef711b70d1a5412194d2fdb08
parent b12e0913cbab876d5f5ff81c3c3713f1065203c9
Author: bsandro <email@bsandro.tech>
Date:   Fri, 12 Dec 2025 14:20:03 +0200

day10 cleanup

Diffstat:
Mday10.c | 38+-------------------------------------
1 file changed, 1 insertion(+), 37 deletions(-)

diff --git a/day10.c b/day10.c @@ -67,14 +67,6 @@ void m_light_toggle(Machine *m, int light) { m->lights1[light] = !m->lights1[light]; } -void m_print(Machine *m) { - printf("(%zu) Lights: [", sizeof(Machine)); - for (int i=0;i<m->lights_l;++i) putchar(m->lights[i]?'#':'.'); - printf("] Joltages:"); - for (int i=0;i<m->joltages_l;++i) printf(" %d", m->joltages[i]); - putchar('\n'); -} - void m_btn_press(Machine *m, int b) { Button *btn = &m->buttons[b]; for (int i=0;i<btn->toggles_l;++i) { @@ -114,7 +106,6 @@ int64_t solve_glpk(Machine *m) { int btnl = m->buttons_l; int cntl = m->joltages_l; // matrix of buttons/counters - //int *matbc = malloc(sizeof(int) * btnl * cntl); int matbc[btnl][cntl]; for (int b=0;b<btnl;++b) { for (int c=0;c<cntl;++c) { @@ -122,20 +113,13 @@ int64_t solve_glpk(Machine *m) { } } - for (int b=0;b<btnl;++b) { - for (int c=0;c<cntl;++c) { - putchar(printf("%2d", matbc[b][c])); - } - printf("\n"); - } - glp_prob *prob = glp_create_prob(); glp_set_prob_name(prob, "aoc2025_d10p2"); glp_set_obj_dir(prob, GLP_MIN); glp_add_rows(prob, cntl); for (int i=0;i<cntl;++i) { - glp_set_row_bnds(prob, i+1, GLP_FX, m->joltages[i], 0); // last arg = m->joltages[i] too? + glp_set_row_bnds(prob, i+1, GLP_FX, m->joltages[i], 0); } glp_add_cols(prob, btnl); for (int i=0;i<btnl;++i) { @@ -154,28 +138,13 @@ int64_t solve_glpk(Machine *m) { ar[k++] = matbc[j-1][i-1]; } } -printf("x: %d, y: %d\n", cntl, btnl); - printf("k: %d\n", k); - printf("ia:"); - for (int i=1;i<k;++i) printf(" %d", ia[i]); - printf("\n"); - printf("ja:"); - for (int i=1;i<k;++i) printf(" %d", ja[i]); - printf("\n"); - printf("ar:"); - for (int i=1;i<k;++i) printf(" %.0f", ar[i]); - printf("\n"); - glp_load_matrix(prob, btnl*cntl, ia, ja, ar); - glp_iocp param; glp_init_iocp(&param); param.msg_lev = GLP_MSG_OFF; param.presolve = GLP_ON; - glp_intopt(prob, &param); int64_t ret = glp_mip_obj_val(prob); - printf("ret: %"PRIi64"\n", ret); glp_delete_prob(prob); return ret; } @@ -210,9 +179,6 @@ int main(void) { int64_t part1 = 0; int64_t part2 = 0; for (int i=0;i<machines_l;++i) { - //printf("---- Machine %p ----\n", &machines[i]); - //printf("%d buttons\n", machines[i].buttons_l); - //m_print(&machines[i]); for (int j=1;j<=20;++j) { if (m_try_start(machines[i], j)) { part1 += j; @@ -224,5 +190,3 @@ int main(void) { printf("p1: %"PRIi64"\np2: %"PRIi64"\n", part1, part2); return 0; } - -// part 2 answer: 20002