summary refs log tree commit diff homepage
path: root/2020/day09.c
blob: f67fb4ee955af2029fa780577ff629c1b0c4a5b4 (plain) (blame)
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
#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;
		}
	}
}