Day 7a
This commit is contained in:
parent
7af9677207
commit
829128a5be
|
@ -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))
|
Loading…
Reference in New Issue