From 2c7509233aebb59f2168b27e3d704dc0d6ad725f Mon Sep 17 00:00:00 2001 From: Christian Neukirchen Date: Tue, 15 Dec 2015 15:14:32 +0100 Subject: day15 --- day15 | 4 ++++ day15.k | 12 ++++++++++++ day15.rb | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 day15 create mode 100644 day15.k create mode 100644 day15.rb 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 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 -- cgit 1.4.1