diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2023-12-25 17:56:34 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2023-12-25 17:56:34 +0100 |
| commit | 94d0033ed89bb5bfb6500051296892fb7cea6c29 (patch) | |
| tree | 245eac2218310c958c2df2fad5109ea4f7b2a9d9 /2023/02/2b.c | |
| parent | 6a480c4eb9c96c82a8fd3663f0fbee4d32e56f19 (diff) | |
| download | aoc-94d0033ed89bb5bfb6500051296892fb7cea6c29.tar.gz aoc-94d0033ed89bb5bfb6500051296892fb7cea6c29.zip | |
Small cleanup
Diffstat (limited to '2023/02/2b.c')
| -rw-r--r-- | 2023/02/2b.c | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/2023/02/2b.c b/2023/02/2b.c index 1b30114..9d7f357 100644 --- a/2023/02/2b.c +++ b/2023/02/2b.c | |||
| @@ -1,11 +1,8 @@ | |||
| 1 | #include <stdbool.h> | ||
| 2 | #include <stdio.h> | 1 | #include <stdio.h> |
| 3 | #include <stdlib.h> | 2 | #include <stdlib.h> |
| 4 | #include <string.h> | ||
| 5 | 3 | ||
| 6 | #define N 10000 | 4 | #define N 10000 |
| 7 | 5 | #define MAX(x,y) ((x)>(y)?(x):(y)) | |
| 8 | #define MAX(x, y) ((x)>(y) ? (x) : (y)) | ||
| 9 | 6 | ||
| 10 | int color[26] = { ['r'-'a'] = 0, ['g'-'a'] = 1, ['b'-'a'] = 2 }; | 7 | int color[26] = { ['r'-'a'] = 0, ['g'-'a'] = 1, ['b'-'a'] = 2 }; |
| 11 | 8 | ||
| @@ -18,11 +15,9 @@ int main() { | |||
| 18 | maxc[0] = maxc[1] = maxc[2] = 0; | 15 | maxc[0] = maxc[1] = maxc[2] = 0; |
| 19 | while (*buf++ != ':'); | 16 | while (*buf++ != ':'); |
| 20 | while (*buf++) { | 17 | while (*buf++) { |
| 21 | if (*buf < '0' || *buf > '9') | 18 | if (*buf < '0' || *buf > '9') continue; |
| 22 | continue; | ||
| 23 | x = atoi(buf); | 19 | x = atoi(buf); |
| 24 | while (*buf < 'a' || *buf > 'z') | 20 | while (*buf < 'a' || *buf > 'z') buf++; |
| 25 | buf++; | ||
| 26 | maxc[color[*buf-'a']] = MAX(maxc[color[*buf-'a']], x); | 21 | maxc[color[*buf-'a']] = MAX(maxc[color[*buf-'a']], x); |
| 27 | } | 22 | } |
| 28 | sum += maxc[0] * maxc[1] * maxc[2]; | 23 | sum += maxc[0] * maxc[1] * maxc[2]; |
