Index: aoc2024.c ================================================================== --- aoc2024.c +++ aoc2024.c @@ -1,10 +1,39 @@ +#include #include #include #include #include "aocutils.h" + +void aoc202403(char *data, [[maybe_unused]] size_t len) { + int sumproducts = 0, term[2]; + char *rest = data; + for (;;) { + char *mul = strstr(rest, "mul("); + if (mul) { + rest = mul + 4; + if (isdigit((unsigned char)rest[0])) { + char *err; + term[0] = (int)strtol(rest, &err, 10); + if (*err == ',') { + if (isdigit((unsigned char)err[1])) { + rest = err + 1; + term[1] = (int)strtol(rest, &err, 10); + if (*err == ')') { + sumproducts += term[0] * term[1]; + rest = err + 1; + } + } + } + } + } else { + break; + } + } + printf("The sum of the products is {%d}.\n", sumproducts); +} static int safereport(int *v, int nv) { int dir = 1; // ascending if (v[0] > v[1]) dir = -1; // descending for (int k = 1; k < nv; k++) { Index: aocdailies.c ================================================================== --- aocdailies.c +++ aocdailies.c @@ -34,8 +34,9 @@ case 201525: p = aoc201525; break; #endif case 202401: p = aoc202401; break; case 202402: p = aoc202402; break; + case 202403: p = aoc202403; break; } return p; } Index: aocdailies.h ================================================================== --- aocdailies.h +++ aocdailies.h @@ -34,7 +34,8 @@ aocfunc aoc201525; #endif aocfunc aoc202401; aocfunc aoc202402; +aocfunc aoc202403; #endif