From 3564c0d80563a4210a29db489b0b561119568068 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Sat, 9 Dec 2023 15:33:05 -0500 Subject: Solve day 2 part 2 --- 2023/day02.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to '2023') diff --git a/2023/day02.c b/2023/day02.c index d24fb17..199f647 100644 --- a/2023/day02.c +++ b/2023/day02.c @@ -2,16 +2,21 @@ #include int main(void) { int game; - int sum = 0; + int sum = 0, powers = 0; while (1 == scanf("Game %d: ", &game)) { - int n; - char c[6]; - while (scanf("%d %5[a-z]%*c", &n, c) > 0) { + 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); } -- cgit 1.4.1