diff --git a/src/2021/01.c b/src/2021/01.c index 22621a6..6f3bcf9 100644 --- a/src/2021/01.c +++ b/src/2021/01.c @@ -4,7 +4,25 @@ #include "input.h" void advent2021day01(void) { - char *input = get_input("input/2021/01"); - printf("Solution for Day 01 of 2021 is not completed yet\n"); + size_t sz = 0; + 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); }