mirror of
https://gitlab.gwdg.de/j.hahn02/university.git
synced 2026-01-01 14:54:25 -05:00
cleanup
This commit is contained in:
60
S1/GdCP/aoc22.c
Normal file
60
S1/GdCP/aoc22.c
Normal file
@@ -0,0 +1,60 @@
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void mix(long *n, long r) { *n = *n ^ r; }
|
||||
void prune(long *n) { *n = *n % 16777216; }
|
||||
|
||||
int main() {
|
||||
FILE *file = fopen("22.in", "r");
|
||||
if (!file) {
|
||||
perror("Unable to open file");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int *array = malloc(10 * sizeof(int));
|
||||
if (!array) {
|
||||
perror("Memory allocation failed");
|
||||
fclose(file);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int num, size = 0, capacity = 10;
|
||||
while (fscanf(file, "%d", &num) == 1) {
|
||||
if (size == capacity) {
|
||||
capacity *= 2;
|
||||
array = realloc(array, capacity * sizeof(int));
|
||||
if (!array) {
|
||||
perror("Memory allocation failed");
|
||||
fclose(file);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
array[size++] = num;
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
|
||||
long r, r1, r2, r3 = 0;
|
||||
for (int i = 0; i < size; i++) {
|
||||
long n = array[i];
|
||||
for (int s = 0; s < 2000; s++) {
|
||||
r1 = n * 64;
|
||||
mix(&n, r1);
|
||||
prune(&n);
|
||||
|
||||
r2 = floor(n / 32.0);
|
||||
mix(&n, r2);
|
||||
prune(&n);
|
||||
|
||||
r3 = n * 2048;
|
||||
mix(&n, r3);
|
||||
prune(&n);
|
||||
}
|
||||
r += n;
|
||||
}
|
||||
printf("%li\n", r);
|
||||
|
||||
free(array);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user