committing everything squashed

This commit is contained in:
2023-12-03 01:12:13 -08:00
commit 92caa0f5c4
15 changed files with 1587 additions and 0 deletions

28
02/part2.c Normal file
View File

@@ -0,0 +1,28 @@
#include <stdio.h>
#include <stdlib.h>
#define MAX_LENGTH 165
int main(void) {
char buf[MAX_LENGTH];
int color_num, sum, max_r, max_g, max_b;
sum = 0;
while (fgets(buf, MAX_LENGTH, stdin)) {
char* c = buf + 5; // +5 skips the "Game "
for (; *c != ':'; c++);
max_r = max_g = max_b = 0;
while (*c != '\n') {
color_num = strtol(c + 2, &c, 10); // +2 skips ": ", ", " or "; "
c++; // +1 skips the space
max_r = (*c == 'r' && color_num > max_r) ? color_num : max_r;
max_g = (*c == 'g' && color_num > max_g) ? color_num : max_g;
max_b = (*c == 'b' && color_num > max_b) ? color_num : max_b;
for (; *c >= 'a' && *c <= 'z'; c++);
}
sum += max_r * max_g * max_b;
}
printf("%d\n", sum);
return 0;
}