Skip to content

Instantly share code, notes, and snippets.

@umgefahren
Created October 8, 2022 12:37
Show Gist options
  • Save umgefahren/fc9a4e98033f04c4d332e46e0ea59369 to your computer and use it in GitHub Desktop.
Save umgefahren/fc9a4e98033f04c4d332e46e0ea59369 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdint.h>
int main() {
FILE * inp_file = fopen("input.txt", "r");
uint64_t a = 0;
uint64_t b = 0;
uint64_t c = 0;
uint64_t slider = 0;
uint64_t incremented = 0;
for (;;) {
uint64_t current_depth;
int output = fscanf(inp_file, "%llu\n", &current_depth);
if (output == EOF) {
break;
}
uint64_t last_sum = a + b + c;
a = b;
b = c;
c = current_depth;
uint64_t current_sum = a + b + c;
if (current_sum > last_sum && slider >= 3)
incremented += 1;
slider += 1;
}
printf("Counter => %llu", incremented);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment