C 2024 day 22 part 1

This commit is contained in:
Bill Rossi 2024-12-24 22:39:41 -05:00
parent 1ba08f9385
commit 90e02ade43

43
c/2024/22/monkey_market.c Normal file
View File

@ -0,0 +1,43 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "../../lib/aoc.h"
void mix(long *secret, long value) {
*secret = *secret ^ value;
}
void prune(long *secret) {
*secret %= 16777216l;
}
int main() {
char *line;
long secret;
long answer = 0;
while ((line = aoc_read_line()) != NULL) {
secret = atol(line);
for (int i = 0; i < 2000; i++) {
long guy = secret * 64;
mix(&secret, guy);
prune(&secret);
guy = secret / 32;
mix(&secret, guy);
prune(&secret);
guy = secret * 2048;
mix(&secret, guy);
prune(&secret);
}
answer += secret;
}
printf("Part 1: %ld", answer);
aoc_free();
exit(0);
}