This commit is contained in:
Evan Burkey 2021-12-10 11:20:22 -08:00
parent 0dfbe6c183
commit ec2799e884

View File

@ -4,7 +4,25 @@
#include "input.h" #include "input.h"
void advent2021day01(void) { void advent2021day01(void) {
char *input = get_input("input/2021/01"); size_t sz = 0;
printf("Solution for Day 01 of 2021 is not completed yet\n"); int *input = get_ints("input/2021/01", &sz);
size_t trips_sz = sz - 2;
int trips[trips_sz];
int p1 = 0, p2 = 0;
for (size_t i = 2, j = 0; i < sz; ++i, ++j) {
trips[j] = input[i - 2] + input[i - 1] + input[i];
}
for (size_t i = 1; i < sz; ++i) {
if (input[i - 1] < input[i]) {
++p1;
}
if (i < trips_sz && trips[i - 1] < trips[i]) {
++p2;
}
}
printf("%d\n%d\n", p1, p2);
free(input); free(input);
} }