summaryrefslogtreecommitdiff
path: root/1/part1.c
blob: 62ef8529e1d5ab5fe244e6194f394d3c48faf8f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define INPUT_LEN 200

int repair(const 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);
    }

    fclose(file);

    printf("%i", repair(input));
}