diff options
author | June McEnroe <june@causal.agency> | 2018-12-08 21:43:35 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2018-12-08 21:43:35 -0500 |
commit | 4d8a7d4dabac4088c3308e1dd6febfb072c20554 (patch) | |
tree | afbca3d35d0734464d2042e3b9695fa5af7cfb8d /2018 | |
parent | Solve day 7 part 2 (diff) | |
download | aoc-4d8a7d4dabac4088c3308e1dd6febfb072c20554.tar.gz aoc-4d8a7d4dabac4088c3308e1dd6febfb072c20554.zip |
Solve day 8 part 1
Diffstat (limited to '2018')
-rw-r--r-- | 2018/day08.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/2018/day08.c b/2018/day08.c new file mode 100644 index 0000000..a240786 --- /dev/null +++ b/2018/day08.c @@ -0,0 +1,28 @@ +#include <stdio.h> +#include <stdlib.h> + +typedef unsigned uint; + +static uint sum; + +static void meta(void) { + uint meta; + scanf("%u", &meta); + sum += meta; +} + +static void node(void) { + uint nchild, nmeta; + scanf("%u %u", &nchild, &nmeta); + for (uint i = 0; i < nchild; ++i) { + node(); + } + for (uint i = 0; i < nmeta; ++i) { + meta(); + } +} + +int main() { + node(); + printf("%u\n", sum); +} |