diff options
Diffstat (limited to '2018/day08.c')
-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); +} |