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 | 234def612fc4514e0a5ef4b43f2c4c6095b76c24 (patch) | |
tree | 528b85855c2d12b3affae11e6ccfaf6b2876e846 /2020/day09.c | |
parent | Solve day 8 part 2 (diff) | |
download | aoc-234def612fc4514e0a5ef4b43f2c4c6095b76c24.tar.gz aoc-234def612fc4514e0a5ef4b43f2c4c6095b76c24.zip |
Solve day 9 part 1
Diffstat (limited to '')
-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; + } + } +} |