about summary refs log tree commit diff
path: root/day15.rb
diff options
context:
space:
mode:
Diffstat (limited to 'day15.rb')
-rw-r--r--day15.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/day15.rb b/day15.rb
new file mode 100644
index 0000000..fdf4ab8
--- /dev/null
+++ b/day15.rb
@@ -0,0 +1,35 @@
+d = File.readlines("day15")
+
+sc = []
+
+(1..100).to_a.repeated_permutation(d.size-1) { |z|
+  r = 100 - z.inject(:+)
+  if r > 0
+    z = z+[r]
+
+    p d.map.with_index { |line,i| [z[i], line.split[2].to_i] }
+    
+    x = [2,4,6,8].map { |f|
+      v = 0
+      d.each.with_index { |line, i|
+        v += z[i] * line.split[f].to_i
+      }
+      [v,0].max
+    }
+    
+    c = 0
+      d.each.with_index { |line, i|
+        c += z[i] * line.split[10].to_i
+      }
+
+      next  unless c == 500
+
+    p [:YES, x]  if x[0] != 0
+    if x.inject(:*) > 0
+      sc << x.inject(:*)
+      p sc.last
+    end
+  end
+}
+
+p sc.max