-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day07Task1.py
29 lines (22 loc) · 892 Bytes
/
Day07Task1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
with open("/Users/DominikKloepfer/Documents/workspace/Personal_Projects/Advent of Code 2018/Day 7/day7_input1.txt") as input:
conditions = [line.strip().split(' ') for line in input]
steps = {} # each key has value [[predecessors], [successors]]
for condition in conditions:
if not condition[1] in steps:
steps[condition[1]] = [[], [condition[7]]]
else:
steps[condition[1]][1].append(condition[7])
if not condition[7] in steps:
steps[condition[7]] = [[condition[1]], []]
else:
steps[condition[7]][0].append(condition[1])
order_of_steps = ''
while len(steps) > 0:
for step in sorted(steps.keys()):
if steps[step][0] == []:
order_of_steps += step
for successor in steps[step][1]:
steps[successor][0].remove(step)
del steps[step]
break
print(order_of_steps)