diff options
| author | June McEnroe <june@causal.agency> | 2020-12-09 00:20:49 -0500 |
|---|---|---|
| committer | June McEnroe <june@causal.agency> | 2020-12-09 00:20:49 -0500 |
| commit | 885a785f92e3761055de67c128be28c62208892b (patch) | |
| tree | a2148db0ee2336ab5afda0e78408e126e8fa88a3 /2020/day09.c | |
| parent | Solve day 8 part 2 (diff) | |
| download | aoc-885a785f92e3761055de67c128be28c62208892b.tar.gz aoc-885a785f92e3761055de67c128be28c62208892b.zip | |
Solve day 9 part 1
Diffstat (limited to '2020/day09.c')
| -rw-r--r-- | 2020/day09.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/2020/day09.c b/2020/day09.c new file mode 100644 index 0000000..f67fb4e --- /dev/null +++ b/2020/day09.c @@ -0,0 +1,28 @@ +#include <stdio.h> +#include <stdlib.h> +enum { Cap = 25 }; +static int ring[Cap]; +static size_t index; +static void push(int x) { + ring[index++ % Cap] = x; +} +static int valid(int x) { + for (int i = 0; i < Cap; ++i) { + for (int j = 0; j < Cap; ++j) { + if (ring[i] == ring[j]) continue; + if (ring[i] + ring[j] == x) return 1; + } + } + return 0; +} +int main(void) { + int x; + while (EOF != scanf("%d\n", &x)) { + if (index < Cap || valid(x)) { + push(x); + } else { + printf("%d\n", x); + break; + } + } +} |