diff options
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; + } + } +} |