summary refs log tree commit diff homepage
path: root/2018
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-12-08 21:43:35 -0500
committerJune McEnroe <june@causal.agency>2018-12-08 21:43:35 -0500
commit4d8a7d4dabac4088c3308e1dd6febfb072c20554 (patch)
treeafbca3d35d0734464d2042e3b9695fa5af7cfb8d /2018
parentSolve day 7 part 2 (diff)
downloadaoc-4d8a7d4dabac4088c3308e1dd6febfb072c20554.tar.gz
aoc-4d8a7d4dabac4088c3308e1dd6febfb072c20554.zip
Solve day 8 part 1
Diffstat (limited to '2018')
-rw-r--r--2018/day08.c28
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);
+}