Skip to content

Instantly share code, notes, and snippets.

@cspickert
Created January 29, 2020 02:05
Show Gist options
  • Save cspickert/2455c04e711f379eea297c9ceab37b63 to your computer and use it in GitHub Desktop.
Save cspickert/2455c04e711f379eea297c9ceab37b63 to your computer and use it in GitHub Desktop.
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