From 829128a5be127e8df060067c8a07bf8ccd6ce74d Mon Sep 17 00:00:00 2001 From: Sijmen Schoon Date: Fri, 7 Dec 2018 08:07:03 +0100 Subject: [PATCH] Day 7a --- Day7/Day7.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Day7/Day7.py diff --git a/Day7/Day7.py b/Day7/Day7.py new file mode 100644 index 0000000..5448acb --- /dev/null +++ b/Day7/Day7.py @@ -0,0 +1,27 @@ +import fileinput +from collections import defaultdict + +def work_seconds(node): + return ord(node) - ord('A') + 60 + +graph = defaultdict(set) +for line in fileinput.input(): + a = line[5] + b = line[36] + + graph[b].add(a) + graph[a] + +order = [] +to_consider = sorted(graph.keys()) +while to_consider: + for i, node in enumerate(to_consider): + parents = graph[node] + if any(parent in to_consider for parent in parents): + continue + + order.append(node) + del to_consider[i] + break + +print("".join(order))