about summary refs log tree commit diff
path: root/day19.rb
diff options
context:
space:
mode:
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