From 736823f313bd2e00e49a1b52aaf0ea68a79db438 Mon Sep 17 00:00:00 2001 From: Vincent Douillet Date: Fri, 3 Dec 2021 17:01:37 +0100 Subject: improve input handling & merge part 1 and 2 for the first days --- 012.c | 39 --------------------------------------- 1 file changed, 39 deletions(-) delete mode 100644 012.c (limited to '012.c') diff --git a/012.c b/012.c deleted file mode 100644 index ac5b057..0000000 --- a/012.c +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include -#include "input.h" - -#define INPUT "input/01.txt" - -int main() { - // lecture du fichier d'entree - FILE* file=fopen(INPUT,"r"); - if(file == NULL) { - printf("Le fichier %s n'existe pas\n", INPUT); - return -1; - } - size_t lineCount = count_lines(file); - int* input = malloc(lineCount * sizeof(int)); - if(read_lines_as_int(file, input, lineCount) != 0) { - printf("Erreur de parsing du fichier\n"); - return -1; - } - // fermeture du fichier - fclose(file); - - // calcul des variations de profondeur - int result = 0; - int windowSum = input[0] + input[1] + input[2]; - for(size_t i = 1; i < lineCount - 2; i++) { - int newWindowSum = input[i] + input[i+1] + input[i+2]; - if(newWindowSum > windowSum) - result++; - - windowSum = newWindowSum; - } - printf("%d\n", result); - - // nettoyage - free(input); - - return 0; -} -- cgit v1.2.3