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))