advent2025

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

commit b609d1484f17b56f2fb95e74019e25be48948f9c
parent 3637ea9d48f67da86ae03baa0f31aa9ae6e54781
Author: bsandro <email@bsandro.tech>
Date:   Thu, 11 Dec 2025 07:27:44 +0200

day10 p2 lost interest

Diffstat:
Mday10.c | 21+++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/day10.c b/day10.c @@ -6,6 +6,12 @@ #define BUF_SIZE 256 +int btoi(int bufl, int buf[bufl]) { + int num = 0; + for (int i=0;i<bufl;++i) num = num*10+buf[i]; + return num; +} + typedef struct { int toggles_l; int toggles[16]; @@ -17,7 +23,8 @@ typedef struct { bool lights1[16];//overall value that we can change int buttons_l; Button buttons[16]; - int presses; + int joltajes_l; + int joltages[16]; // same number as lights } Machine; void m_lights_add(Machine *m, int buf_l, char buf[buf_l]) { @@ -40,13 +47,14 @@ bool m_lights_on(Machine *m) { return true; } +//@todo use XOR 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) printf("%c", m->lights1[i]?'#':'.'); + for (int i=0;i<m->lights_l;++i) printf("%c", m->lights[i]?'#':'.'); printf("]\n"); } @@ -55,7 +63,6 @@ void m_btn_press(Machine *m, int b) { for (int i=0;i<btn->toggles_l;++i) { m_light_toggle(m, btn->toggles[i]); } - m->presses++; } void m_btn_press_many(Machine *m, int comb_l, int comb[comb_l]) { @@ -75,7 +82,7 @@ bool try_combination(Machine *m, int comb_l, int comb[comb_l], int p) { //puts("after:"); //m_print(&m1); if (m_lights_on(&m1)) { - puts("ok"); + //puts("ok"); return true; } //return m_lights_on(&m1); @@ -123,9 +130,9 @@ int main(void) { printf("%d buttons\n", machines[i].buttons_l); m_print(&machines[i]); for (int j=1;j<=20;++j) { - printf("try start %i with %d button presses\n", i, j); + //printf("try start %i with %d button presses\n", i, j); if (m_try_start(machines[i], j)) { - printf("%d presses start ok\n", j); + //printf("%d presses start ok\n", j); part1 += j; break; } @@ -134,3 +141,5 @@ int main(void) { printf("p1: %"PRIi64"\np2: %"PRIi64"\n", part1, part2); return 0; } + +// part 2 answer: 20002