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>2020-11-22 00:14:25 -0500
commitbf1feb3ee2693f6eef33287d4ba391c07f1a9a8c (patch)
tree27cd473a969b9c0efe84c4ce0e1080006574680f /2018
parentSolve day 7 part 2 (diff)
downloadaoc-bf1feb3ee2693f6eef33287d4ba391c07f1a9a8c.tar.gz
aoc-bf1feb3ee2693f6eef33287d4ba391c07f1a9a8c.zip
Solve day 8 part 1
Diffstat (limited to '')
-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);
+}