diff options
author | June McEnroe <june@causal.agency> | 2023-12-09 15:33:05 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2023-12-09 15:33:05 -0500 |
commit | 3564c0d80563a4210a29db489b0b561119568068 (patch) | |
tree | 4d4f3251b845741be4b5aca216a2bcc996b586df | |
parent | Solve day 2 part 1 (diff) | |
download | aoc-3564c0d80563a4210a29db489b0b561119568068.tar.gz aoc-3564c0d80563a4210a29db489b0b561119568068.zip |
Solve day 2 part 2
Diffstat (limited to '')
-rw-r--r-- | 2023/day02.c | 13 |
1 files changed, 9 insertions, 4 deletions
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 <stdlib.h> 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); } |