about summary refs log tree commit diff
path: root/aoc/2024/05/part-one.c
blob: 4d2b560038936cdf4f6b23bbe935b91d9fd9db84 (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
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
	bool after[100][100] = {false};
	unsigned char x, y;
	while (scanf("%hhu|%hhu\n", &x, &y) == 2)
		after[y][x] = true;

	unsigned char line[90];
	unsigned sum = y = 0;
	do {
		bool right = true;
		do {
			line[y] = x;
			for (unsigned char i = 0; right && i < y; ++i)
				if (after[line[i]][line[y]])
					right = false;
		} while (scanf(",%hhu", &x) == 1 && ++y);
		if (right)
			sum += line[y + 1 >> 1];
	} while (y = 0, scanf("%hhu", &x) == 1);
	printf("%u\n", sum);
	return 0;
}