about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2015-12-15 15:14:32 +0100
committerChristian Neukirchen <chneukirchen@gmail.com>2015-12-15 15:14:32 +0100
commit2c7509233aebb59f2168b27e3d704dc0d6ad725f (patch)
treed5ae578ba6602f34a1c3e0b95f5a9006c222f10d
parente8ee73c2b058529ee427f89e388dc012bc354fbb (diff)
downloadadventofcode2015-2c7509233aebb59f2168b27e3d704dc0d6ad725f.tar.gz
adventofcode2015-2c7509233aebb59f2168b27e3d704dc0d6ad725f.tar.xz
adventofcode2015-2c7509233aebb59f2168b27e3d704dc0d6ad725f.zip
day15
-rw-r--r--day154
-rw-r--r--day15.k12
-rw-r--r--day15.rb35
3 files changed, 51 insertions, 0 deletions
diff --git a/day15 b/day15
new file mode 100644
index 0000000..d1af06e
--- /dev/null
+++ b/day15
@@ -0,0 +1,4 @@
+Sugar: capacity 3, durability 0, flavor 0, texture -3, calories 2
+Sprinkles: capacity -3, durability 3, flavor 0, texture 0, calories 9
+Candy: capacity -1, durability 0, flavor 4, texture 0, calories 1
+Chocolate: capacity 0, durability 0, flavor -2, texture 2, calories 8
diff --git a/day15.k b/day15.k
new file mode 100644
index 0000000..241f5fe
--- /dev/null
+++ b/day15.k
@@ -0,0 +1,12 @@
+d:0:"day15";
+ss:{1 _' (&y=y,x) _ y,x}; / split x at y
+l:ss[;" "]' d;
+v:{0$' -1 _' x@2 4 6 8}'l; / valuations
+c:{0$' -1 _' x@10}'l; / calories
+
+n:{x,100-+/x}'!3#100;
+n:n@&&/'1<n; / only positive ingredients
+|/{*/0|+/v*x}'n
+
+n:n@&{500=+/c*x}'n; / only 500 calories
+|/{*/0|+/v*x}'n
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