aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2018-12-11 14:28:43 +0100
committerLeah Neukirchen <leah@vuxu.org>2018-12-11 14:28:43 +0100
commite7881fdf30aa81bd7e5ce1790791cb5fd537584c (patch)
treeb17fa62dbe1e7800ac8a93966a04b2d61f64ceab
parent116b36c06e24e3fc9bac5c2bbe0385305f0fc148 (diff)
downloadadventofcode2018-e7881fdf30aa81bd7e5ce1790791cb5fd537584c.tar.gz
adventofcode2018-e7881fdf30aa81bd7e5ce1790791cb5fd537584c.tar.xz
adventofcode2018-e7881fdf30aa81bd7e5ce1790791cb5fd537584c.zip
day07
-rw-r--r--day07101
-rw-r--r--day07.rb52
2 files changed, 153 insertions, 0 deletions
diff --git a/day07 b/day07
new file mode 100644
index 0000000..0197b6d
--- /dev/null
+++ b/day07
@@ -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.
diff --git a/day07.rb b/day07.rb
new file mode 100644
index 0000000..4793c3e
--- /dev/null
+++ b/day07.rb
@@ -0,0 +1,52 @@
+p1 = {}
+p2 = {}
+
+IO.foreach("day07") { |line|
+ (p1[line[36]] ||= []) << line[5]
+ (p2[line[5]] ||= []) << line[36]
+ p2[line[36]] ||= []
+}
+
+q = p1.values.concat.flatten - p1.keys
+
+fin = []
+until q.empty?
+ q.sort!
+ q.uniq!
+ c = q.shift
+
+ print c unless fin.include? c
+ fin << c
+
+ p1.each { |k,v|
+ q << k if (v - fin).empty? && !fin.include?(k)
+ }
+end
+puts # BDHNEGOLQASVWYPXUMZJIKRTFC
+
+
+t = 0
+w = [nil]*5
+
+until p2.empty?
+ w.each_with_index { |j, i|
+ if j && j[1] == t
+ w[i] = nil
+ p2.delete(j[0])
+ end
+ }
+
+ w.each_with_index { |j, i|
+ if !j && wn = p2.keys.find { |n|
+ p2.none? { |k,v| v.include? n } && w.none? { |j| j && n.include?(j[0]) }
+ }
+ w[i] = [wn, t + wn.ord - 64 + 60]
+ end
+ }
+
+ t += 1
+end
+
+p t-1
+
+# 1107