Index: aoc2025.c ================================================================== --- aoc2025.c +++ aoc2025.c @@ -13,18 +13,73 @@ void aocYYYYDD(char *data, size_t len) { (void)len; // unused argument } #endif + +/* === aoc202506 ======================================================= +===================================================================== */ +static long long unsigned add2506(long long unsigned v[4][1024], int lin, int col) { + long long unsigned sum = 0; + for (int k = 0; k < lin; k++) sum += v[k][col]; + return sum; +} +static long long unsigned mul2506(long long unsigned v[4][1024], int lin, int col) { + long long unsigned sum = 1; + for (int k = 0; k < lin; k++) sum *= v[k][col]; + return sum; +} + +static long long unsigned input_202506[4][1024]; +void aoc202506(char *data, size_t len) { + (void)len; // unused argument + char *X; + for (;;) { + X = strchr(data, '\n'); + if (!X) break; + *X = 'X'; + } + int lin = 0, col; + char *err = data; + for (;;) { // for each line + col = 0; + for (;;) { // for each number + while (isspace(*err)) err++; + long long unsigned tmp = strtoull(err, &err, 10); + if ((*err == 'X') && (tmp == 0)) { err++; break; } + input_202506[lin][col++] = tmp; + } + lin++; + printf("got line %d with %d columns\n", lin, col); + if ((*err == '+') || (*err == '*')) break; + } + printf("from %llu to %llu\n", input_202506[0][0], input_202506[lin-1][col-1]); + col = 0; + while (isspace(*err)) err++; + long long unsigned sum = 0; + for (;;) { + switch (*err) { + default: /* does not happen! */ break; + case 'X': break; + case '+': sum += add2506(input_202506, lin, col); break; + case '*': sum += mul2506(input_202506, lin, col); break; + } + if (*err == 'X') break; + col++; + err++; + while (isspace(*err)) err++; + } + printf("part 1: %llu\n", sum); +} /* === aoc202505 ======================================================= ===================================================================== */ struct Range { long long unsigned lo, hi; }; -int ascending(const void *a, const void *b) { +static int ascending(const void *a, const void *b) { const struct Range *aa = a, *bb = b; if (aa->lo < bb->lo) return -1; if (aa->lo > bb->lo) return 1; return 0; } Index: aocdailies.c ================================================================== --- aocdailies.c +++ aocdailies.c @@ -4,10 +4,11 @@ aocfunc *aocselect(unsigned y, unsigned d) { aocfunc *p; switch (y * 100 + d) { default: p = NULL; break; + case 202506: p = aoc202506; break; case 202505: p = aoc202505; break; case 202504: p = aoc202504; break; case 202503: p = aoc202503; break; case 202502: p = aoc202502; break; case 202501: p = aoc202501; break; Index: aocdailies.h ================================================================== --- aocdailies.h +++ aocdailies.h @@ -4,10 +4,11 @@ #include typedef void aocfunc(char *, size_t); aocfunc *aocselect(unsigned, unsigned); +aocfunc aoc202506; aocfunc aoc202505; aocfunc aoc202504; aocfunc aoc202503; aocfunc aoc202502; aocfunc aoc202501;