about summary refs log tree commit diff
path: root/day19.rb
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2015-12-19 19:20:38 +0100
committerChristian Neukirchen <chneukirchen@gmail.com>2015-12-19 19:20:38 +0100
commitbff8b596a3a6ff4b363801fa058f1f35bc328ecf (patch)
tree444355a96b9177b9b18fe269bc15658d8553549a /day19.rb
parent16625179ec285a8d5c70b459e29fd8d2c33771f9 (diff)
downloadadventofcode2015-bff8b596a3a6ff4b363801fa058f1f35bc328ecf.tar.gz
adventofcode2015-bff8b596a3a6ff4b363801fa058f1f35bc328ecf.tar.xz
adventofcode2015-bff8b596a3a6ff4b363801fa058f1f35bc328ecf.zip
day19
Diffstat (limited to 'day19.rb')
-rw-r--r--day19.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/day19.rb b/day19.rb
new file mode 100644
index 0000000..e89547c
--- /dev/null
+++ b/day19.rb
@@ -0,0 +1,31 @@
+f = File.readlines("day19")
+
+r = f.pop.chomp
+f.pop
+
+$m = f.map { |x| x.chomp.split(" => ") }
+
+def ssall(t, s, r)
+  z = []
+  t.scan(s) { z << $`+r+$' }
+  z.uniq
+end
+
+p $m.map { |s,r_| ssall(r, s, r_) }.flatten.uniq.size
+
+
+a = [r]
+c = 0
+until a.include?("e") || a.empty?
+  c += 1
+  a = a.map { |t|
+    $m.map { |s,r|
+      ssall(t, r, s)
+    }
+  }.flatten.uniq
+  ms = a.map{|t|t.size}.min
+  a.delete_if { |t| t.size > ms }
+  a = a.first(100)
+end
+
+p c