diff options
author | Nguyễn Gia Phong <cnx@loang.net> | 2024-12-03 16:14:38 +0900 |
---|---|---|
committer | Nguyễn Gia Phong <cnx@loang.net> | 2024-12-03 16:14:38 +0900 |
commit | 8026395b987f440486e215f77e402eafc94160f0 (patch) | |
tree | 243cd5c625d25aeead1659be1c3b462abeda81c4 | |
parent | 23ff5e1a6cd78601f24e50fbf21406bb8179d2af (diff) | |
download | cp-8026395b987f440486e215f77e402eafc94160f0.tar.gz |
[aoc/2024] Finish day 3
-rw-r--r-- | aoc/2024/03/part-one.c | 11 | ||||
-rw-r--r-- | aoc/2024/03/part-two.c | 27 |
2 files changed, 38 insertions, 0 deletions
diff --git a/aoc/2024/03/part-one.c b/aoc/2024/03/part-one.c new file mode 100644 index 0000000..0438304 --- /dev/null +++ b/aoc/2024/03/part-one.c @@ -0,0 +1,11 @@ +#include <stdio.h> + +int main() +{ + size_t x, y, s = 0; + while (scanf("%*[^m]") != EOF) + if (scanf("mul(%3zu,%3zu", &x, &y) == 2 && getchar() == ')') + s += x * y; + printf("%zu\n", s); + return 0; +} diff --git a/aoc/2024/03/part-two.c b/aoc/2024/03/part-two.c new file mode 100644 index 0000000..4ae337f --- /dev/null +++ b/aoc/2024/03/part-two.c @@ -0,0 +1,27 @@ +#include <stdbool.h> +#include <stdio.h> + +int main() +{ + bool d = true; + size_t x, y, s = 0; + while (scanf("%*[^dm]") != EOF) { + if (getchar() == 'd') { + int c; +#define unless(i) if ((c = getchar()) != i && ungetc(c, stdin) == c) + unless ('o') continue; + unless ('(') { + if (scanf("n't()") != EOF) + d = false; + continue; + } + unless (')') continue; +#undef unless + d = true; + } + if (scanf("ul(%3zu,%3zu", &x, &y) == 2 && getchar() == ')' && d) + s += x * y; + } + printf("%zu\n", s); + return 0; +} |