From 67bc63c6efb2cf7192395d4011323fcfdf4473d7 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Fri, 7 Dec 2018 12:32:44 -0500 Subject: Solve day 7 part 1 --- 2018/day07.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 2018/day07.c (limited to '2018') 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 +#include + +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"); +} -- cgit 1.4.1