From d4019c536df8c2abc411825b4501c7a80a83fe0c Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Wed, 2 Dec 2020 20:22:31 +0100 Subject: Add day 1 --- 1/part1.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 1/part1.c (limited to '1/part1.c') diff --git a/1/part1.c b/1/part1.c new file mode 100644 index 0000000..85cbfd7 --- /dev/null +++ b/1/part1.c @@ -0,0 +1,33 @@ +#include +#include +#include +#include + +#define INPUT_LEN 200 + +int repair(int * arr) +{ + for (int i = 0; i < INPUT_LEN; i++) { + for (int j = 0; j < INPUT_LEN; j++) { + if (arr[i] + arr[j] == 2020) { + return arr[i] * arr[j]; + } + } + } + + return 0; +} + +int main() +{ + FILE * file = fopen("input", "r"); + + char buffer[8] = { 0 }; + int input[INPUT_LEN] = { 0 }; + for (int i = 0; i < 200; i++) { + fgets(buffer, 8, file); + input[i] = atoi(buffer); + } + + printf("%i", repair(input)); +} -- cgit v1.2.3