[2017][ruby][7.x] gross
change utoruqvtwnxvtpurqtxkruqyokypnwpo
commit 123a03835b33728d57ecab1d3d63b97e555b9e37
author Alpha Chen <alpha.chen@gmail.com>
date
parent swtmvlol
diff --git a/2017/ruby/day_07.rb b/2017/ruby/day_07.rb
new file mode 100644
index 0000000..b28de74
--- /dev/null
+++ b/2017/ruby/day_07.rb
@@ -0,0 +1,20 @@
+Program = Struct.new(:name, :weight, :disc)
+
+programs = {}
+File.read(File.expand_path("../input/day_07.txt")).strip.split("\n").each do |line|
+  name, weight, above = line.scan(/(.+) \((\d+)\)(?: -> (.+))?/)[0]
+  programs[name] = Program.new(name, weight.to_i, (above || "").split(", "))
+end
+
+disc_weights = Hash.new {|h,k|
+  program = programs[k]
+  h[k] = if program.disc.empty?
+           program.weight
+         else
+           program.weight + program.disc.map {|x| h[programs[x].name] }.sum
+         end
+}
+
+root = "mkxke"
+p programs[root].disc.map {|n| [n, disc_weights[n]] }
+require "pry"; binding.pry