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

29
02/part1.c Normal file
View File

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