diff options
Diffstat (limited to '2023')
-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); } |