summary refs log tree commit diff homepage
path: root/2018/day07.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-12-07 12:32:44 -0500
committerJune McEnroe <june@causal.agency>2020-11-22 00:14:25 -0500
commite4e3bf8f6e0fbca5ea38e34bfa69730727adc5b5 (patch)
tree797d72355cb2705bb0d577f7feba49e461de53e5 /2018/day07.c
parentSolve day 6 part 2 (diff)
downloadaoc-e4e3bf8f6e0fbca5ea38e34bfa69730727adc5b5.tar.gz
aoc-e4e3bf8f6e0fbca5ea38e34bfa69730727adc5b5.zip
Solve day 7 part 1
Diffstat (limited to '2018/day07.c')
-rw-r--r--2018/day07.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/2018/day07.c b/2018/day07.c
new file mode 100644
index 0000000..43dd786
--- /dev/null
+++ b/2018/day07.c
@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+typedef unsigned uint;
+
+int main() {
+	uint steps = 0;
+	uint deps[26] = {0};
+	while (!feof(stdin)) {
+		char dep, step;
+		scanf(
+			"Step %c must be finished before step %c can begin.\n",
+			&dep, &step
+		);
+		deps[step - 'A'] |= 1 << (dep - 'A');
+	}
+	while (steps != (1 << 26) - 1) {
+		for (uint i = 0; i < 26; ++i) {
+			if (steps & (1 << i)) continue;
+			if ((deps[i] & steps) != deps[i]) continue;
+			printf("%c", 'A' + i);
+			steps |= (1 << i);
+			break;
+		}
+	}
+	printf("\n");
+}