Created
January 29, 2020 02:05
-
-
Save cspickert/2455c04e711f379eea297c9ceab37b63 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
tasks = defaultdict(list) | |
for line in open('day7.txt'): | |
components = line.split(' ') | |
dep, task = components[1], components[7] | |
tasks[task].append(dep) | |
if dep not in tasks: tasks[dep] = [] | |
result = '' | |
while tasks: | |
task = next(task for task in sorted(tasks) if not tasks[task]) | |
result += task | |
del tasks[task] | |
for other in tasks: | |
if task in tasks[other]: | |
tasks[other].remove(task) | |
print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment