diff options
| author | Bond_009 <bond.009@outlook.com> | 2020-12-02 20:22:31 +0100 |
|---|---|---|
| committer | Bond_009 <bond.009@outlook.com> | 2020-12-02 20:22:31 +0100 |
| commit | d4019c536df8c2abc411825b4501c7a80a83fe0c (patch) | |
| tree | 596c665dcc364122e357def188110b6c3a641735 /1/part2.c | |
| parent | 928092a7b82bc6dd16926a378b91e24510b9ec0f (diff) | |
Add day 1
Diffstat (limited to '1/part2.c')
| -rw-r--r-- | 1/part2.c | 35 |
1 files changed, 35 insertions, 0 deletions
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 <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#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)); +} |
