This commit is contained in:
Jack Bond-Preston 2018-12-07 06:51:47 +00:00
parent 17692e5d24
commit 4f68af7424
2 changed files with 147 additions and 0 deletions

101
aoc-7/inputs.txt Normal file
View File

@ -0,0 +1,101 @@
Step D must be finished before step L can begin.
Step B must be finished before step G can begin.
Step N must be finished before step Z can begin.
Step V must be finished before step Y can begin.
Step G must be finished before step R can begin.
Step E must be finished before step L can begin.
Step O must be finished before step W can begin.
Step Q must be finished before step X can begin.
Step Y must be finished before step J can begin.
Step W must be finished before step R can begin.
Step H must be finished before step P can begin.
Step L must be finished before step P can begin.
Step X must be finished before step T can begin.
Step S must be finished before step K can begin.
Step U must be finished before step R can begin.
Step P must be finished before step Z can begin.
Step A must be finished before step Z can begin.
Step M must be finished before step F can begin.
Step Z must be finished before step K can begin.
Step J must be finished before step K can begin.
Step I must be finished before step C can begin.
Step K must be finished before step C can begin.
Step R must be finished before step C can begin.
Step T must be finished before step F can begin.
Step F must be finished before step C can begin.
Step E must be finished before step C can begin.
Step H must be finished before step S can begin.
Step X must be finished before step K can begin.
Step E must be finished before step Y can begin.
Step I must be finished before step T can begin.
Step T must be finished before step C can begin.
Step R must be finished before step T can begin.
Step X must be finished before step U can begin.
Step I must be finished before step R can begin.
Step I must be finished before step K can begin.
Step L must be finished before step A can begin.
Step P must be finished before step C can begin.
Step D must be finished before step S can begin.
Step Q must be finished before step A can begin.
Step N must be finished before step G can begin.
Step W must be finished before step P can begin.
Step B must be finished before step E can begin.
Step M must be finished before step T can begin.
Step L must be finished before step C can begin.
Step E must be finished before step F can begin.
Step M must be finished before step I can begin.
Step M must be finished before step Z can begin.
Step U must be finished before step F can begin.
Step W must be finished before step K can begin.
Step E must be finished before step W can begin.
Step B must be finished before step W can begin.
Step A must be finished before step I can begin.
Step M must be finished before step K can begin.
Step X must be finished before step F can begin.
Step O must be finished before step Z can begin.
Step W must be finished before step C can begin.
Step Q must be finished before step M can begin.
Step K must be finished before step R can begin.
Step Y must be finished before step C can begin.
Step A must be finished before step T can begin.
Step G must be finished before step L can begin.
Step G must be finished before step A can begin.
Step J must be finished before step I can begin.
Step N must be finished before step R can begin.
Step D must be finished before step W can begin.
Step L must be finished before step R can begin.
Step Y must be finished before step P can begin.
Step S must be finished before step M can begin.
Step O must be finished before step I can begin.
Step Z must be finished before step J can begin.
Step H must be finished before step M can begin.
Step L must be finished before step K can begin.
Step U must be finished before step M can begin.
Step G must be finished before step T can begin.
Step O must be finished before step L can begin.
Step Z must be finished before step R can begin.
Step N must be finished before step E can begin.
Step U must be finished before step I can begin.
Step G must be finished before step Q can begin.
Step H must be finished before step R can begin.
Step U must be finished before step C can begin.
Step L must be finished before step U can begin.
Step H must be finished before step Z can begin.
Step P must be finished before step F can begin.
Step I must be finished before step F can begin.
Step B must be finished before step N can begin.
Step J must be finished before step R can begin.
Step O must be finished before step S can begin.
Step Y must be finished before step T can begin.
Step G must be finished before step S can begin.
Step N must be finished before step O can begin.
Step Y must be finished before step X can begin.
Step B must be finished before step X can begin.
Step A must be finished before step F can begin.
Step Z must be finished before step I can begin.
Step K must be finished before step F can begin.
Step J must be finished before step C can begin.
Step D must be finished before step G can begin.
Step P must be finished before step M can begin.
Step K must be finished before step T can begin.
Step X must be finished before step M can begin.

46
aoc-7/main.py Normal file
View File

@ -0,0 +1,46 @@
from collections import defaultdict
inputs = open("inputs.txt", "r").read().split('\n')
dependencies = defaultdict(set)
for line in inputs:
dep = line.split()[1]
step = line.split()[7]
dependencies[step].add(dep)
if dep not in dependencies:
dependencies[dep] = set()
steps = []
while len(steps) < len(dependencies):
possibleNextSteps = list()
for key in sorted([ k for k in dependencies.keys() if k not in steps ]):
if dependencies[key].issubset(set(steps)):
possibleNextSteps.append(key)
nextStep = possibleNextSteps[0]
steps.append(nextStep)
print(f"[Part 1] Steps: { ''.join(steps) }")
alpha = list("_ABCDEFGHIJKLMNOPQRSTUVWXYZ")
completedSteps = set()
inProgress = dict()
time = 0
while len(completedSteps) < len(dependencies):
for step in [ step for step in steps if step not in completedSteps and step not in inProgress.keys() ]:
if dependencies[step].issubset(completedSteps) and len(inProgress) < 5:
inProgress[step] = alpha.index(step) + 60
for step in set(inProgress.keys()) - { k for k, v in inProgress.items() if v > 1 }:
completedSteps.add(step)
inProgress = { k : v - 1 for k, v in inProgress.items() if v > 1 }
time += 1
print(f"[Part 2] Time taken: { time }")