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/part2.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 1/part2.c (limited to '1/part2.c') diff --git a/1/part2.c b/1/part2.c new file mode 100644 index 0000000..5842205 --- /dev/null +++ b/1/part2.c @@ -0,0 +1,35 @@ +#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++) { + for (int k = 0; k < INPUT_LEN; k++) { + if (arr[i] + arr[j] + arr[k] == 2020) { + return arr[i] * arr[j] * arr[k]; + } + } + } + } + + 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