about summary refs log tree commit diff
path: root/aoc/2024/03/part-two.c
blob: 4ae337fa28c75c6b2ad605ca1ef22ffe967e440a (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>

int main()
{
	bool d = true;
	size_t x, y, s = 0;
	while (scanf("%*[^dm]") != EOF) {
		if (getchar() == 'd') {
			int c;
#define unless(i) if ((c = getchar()) != i && ungetc(c, stdin) == c)
			unless ('o') continue;
			unless ('(') {
				if (scanf("n't()") != EOF)
					d = false;
				continue;
			}
			unless (')') continue;
#undef unless
			d = true;
		}
		if (scanf("ul(%3zu,%3zu", &x, &y) == 2 && getchar() == ')' && d)
			s += x * y;
	}
	printf("%zu\n", s);
	return 0;
}