44 lines
726 B
C
44 lines
726 B
C
#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);
|
|
}
|