1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
#include <ctype.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "aocdailies.h"
#include "aocutils.h"
/* === 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
(fileid * 10) + length, or, when empty, the negative length
===================================================================== */
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#include <ctype.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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
(fileid * 10) + length, or, when empty, the negative length
===================================================================== */
|