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/part1.c | |
| parent | 928092a7b82bc6dd16926a378b91e24510b9ec0f (diff) | |
Add day 1
Diffstat (limited to '1/part1.c')
| -rw-r--r-- | 1/part1.c | 33 |
1 files changed, 33 insertions, 0 deletions
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 <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++) { + 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)); +} |
