Index: aoc2024.c ================================================================== --- aoc2024.c +++ aoc2024.c @@ -4,10 +4,39 @@ #include #include #include #include "aocdailies.h" #include "aocutils.h" + +/* === aoc202422 ======================================================= +===================================================================== */ +static long long unsigned mix(long long unsigned a, long long unsigned b) { + long long unsigned tmp = a ^ b; + return tmp; +} + +static long long unsigned prune(long long unsigned a) { + return a % 16777216; +} + +void aoc202422(char *data, size_t len) { + (void)len; // unused argument + long long unsigned sum2000 = 0; + char *key = strtok(data, "\n"); + while (key) { + long long unsigned secret; + if (sscanf(key, "%llu", &secret) != 1) break; + for (int k = 0; k < 2000; k++) { + secret = prune(mix(secret * 64, secret)); + secret = prune(mix(secret / 32, secret)); + secret = prune(mix(secret * 2048, secret)); + } + sum2000 += secret; + key = strtok(NULL, "\n"); + } + printf("The sum of all 2000th secrets is {%llu}.\n", sum2000); +} /* === aoc202409 ======================================================= WOW! input consists of a 20,000 long string of numbers! Make an array of blocks, each with either -1 or the fileid For Part Two: make an array of blocks with the encoded value of Index: aocdailies.c ================================================================== --- aocdailies.c +++ aocdailies.c @@ -5,10 +5,11 @@ aocfunc *p; switch (y * 100 + d) { default: p = NULL; break; // YYYYdd ==> aocYYYYdd + case 202422: p = aoc202422; break; case 202409: p = aoc202409; break; case 202408: p = aoc202408; break; case 202407: p = aoc202407; break; case 202406: p = aoc202406; break; case 202405: p = aoc202405; break; Index: aocdailies.h ================================================================== --- aocdailies.h +++ aocdailies.h @@ -4,10 +4,11 @@ #include typedef void aocfunc(char *, size_t); aocfunc *aocselect(unsigned, unsigned); +aocfunc aoc202422; aocfunc aoc202409; aocfunc aoc202408; aocfunc aoc202407; aocfunc aoc202406; aocfunc aoc202405;