diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2023-12-11 15:14:47 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2023-12-11 15:14:47 +0100 |
| commit | 554ad47f09974f0131df285fda8ea50a1fdad8f5 (patch) | |
| tree | d23caeb85e7fce6290664a0ebf3c96f513efbe94 /2023/02/2a.c | |
| download | aoc-554ad47f09974f0131df285fda8ea50a1fdad8f5.tar.gz aoc-554ad47f09974f0131df285fda8ea50a1fdad8f5.zip | |
Initial commit, some solutions
Diffstat (limited to '2023/02/2a.c')
| -rw-r--r-- | 2023/02/2a.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/2023/02/2a.c b/2023/02/2a.c new file mode 100644 index 0000000..f3ddfc8 --- /dev/null +++ b/2023/02/2a.c | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | #include <stdbool.h> | ||
| 2 | #include <stdio.h> | ||
| 3 | #include <stdlib.h> | ||
| 4 | #include <string.h> | ||
| 5 | |||
| 6 | #define N 10000 | ||
| 7 | |||
| 8 | #define MAX(x, y) ((x)>(y) ? (x) : (y)) | ||
| 9 | |||
| 10 | int color[26] = { ['r'-'a'] = 0, ['g'-'a'] = 1, ['b'-'a'] = 2 }; | ||
| 11 | |||
| 12 | int main() { | ||
| 13 | char *buf, line[N]; | ||
| 14 | int i, sum, x, maxc[3]; | ||
| 15 | |||
| 16 | for (i = 1, sum = 0; (buf = fgets(line, N, stdin)) != NULL; i++) { | ||
| 17 | maxc[0] = maxc[1] = maxc[2] = 0; | ||
| 18 | while (*buf++ != ':'); | ||
| 19 | while (*buf++) { | ||
| 20 | if (*buf < '0' || *buf > '9') | ||
| 21 | continue; | ||
| 22 | x = atoi(buf); | ||
| 23 | while (*buf < 'a' || *buf > 'z') | ||
| 24 | buf++; | ||
| 25 | maxc[color[*buf-'a']] = MAX(maxc[color[*buf-'a']], x); | ||
| 26 | } | ||
| 27 | if (maxc[0] <= 12 && maxc[1] <= 13 && maxc[2] <= 14) | ||
| 28 | sum += i; | ||
| 29 | } | ||
| 30 | |||
| 31 | printf("%d\n", sum); | ||
| 32 | return 0; | ||
| 33 | } | ||
