diff options
| author | Bond_009 <bond.009@outlook.com> | 2022-12-01 22:30:22 +0100 |
|---|---|---|
| committer | Bond_009 <bond.009@outlook.com> | 2022-12-01 22:30:22 +0100 |
| commit | baf4910870a6e8999802b9a4a22eabd4142a34e3 (patch) | |
| tree | 2d11443dc21e53bd0d99d015cf789937d6d95862 /9/part1.c | |
| parent | 49d0c908f24b2c193c9deed1716fe36061ba26a1 (diff) | |
Move all Advent of Codes into one repo
Diffstat (limited to '9/part1.c')
| -rw-r--r-- | 9/part1.c | 54 |
1 files changed, 0 insertions, 54 deletions
diff --git a/9/part1.c b/9/part1.c deleted file mode 100644 index d17fb2b..0000000 --- a/9/part1.c +++ /dev/null @@ -1,54 +0,0 @@ -#include <stdbool.h> -#include <stdio.h> -#include <stdint.h> -#include <stdlib.h> - -#define INPUT_LEN 1000 -#define SEARCH_LEN 25 - -bool has_sum(uint64_t *cur_num) -{ - uint64_t search = *cur_num; - uint64_t *p1 = cur_num - SEARCH_LEN; - do { - uint64_t *p2 = cur_num - SEARCH_LEN; - do { - if (*p1 + *p2 == search) { - return true; - } - } while (++p2 < cur_num); - } while (++p1 < cur_num); - - return false; -} - -int exe_program(const char *filename) -{ - FILE *file = fopen(filename, "r"); - - // Include space for newline and string terminator - char buffer[24] = { 0 }; - - uint64_t nums[INPUT_LEN]; - size_t num_size = 0; - - while (fgets(buffer, 24, file)) { - nums[num_size++] = strtoull(buffer, NULL, 10); - } - - fclose(file); - - uint64_t *cur_num = nums + SEARCH_LEN; - do { - if (!has_sum(cur_num)) { - return *cur_num; - } - } while (++cur_num < nums + num_size); - - return -1; -} - -int main(int argc, char *argv[]) -{ - printf("%i\n", exe_program(argv[argc - 1])); -} |
