summary refs log tree commit diff homepage
path: root/2023/day02.c
blob: 199f6474007638cdd9166f072a4f23c0ad207a4e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <stdio.h>
#include <stdlib.h>
int main(void) {
	int game;
	int sum = 0, powers = 0;
	while (1 == scanf("Game %d: ", &game)) {
		int n, r = 0, g = 0, b = 0;
		char c[6], e;
		while (scanf("%d %5[a-z]%c", &n, c, &e) > 0) {
			if (c[0] == 'r' && n > 12) game = 0;
			if (c[0] == 'g' && n > 13) game = 0;
			if (c[0] == 'b' && n > 14) game = 0;
			if (c[0] == 'r' && n > r) r = n;
			if (c[0] == 'g' && n > g) g = n;
			if (c[0] == 'b' && n > b) b = n;
		}
		sum += game;
		powers += r * g * b;
	}
	printf("%d\n", sum);
	printf("%d\n", powers);
}