From b10d0fb910ef1d8862711d3039a46a4441b56272 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Mon, 14 Dec 2015 21:14:48 -0800 Subject: [PATCH] Day 15.0 --- day_15.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 day_15.rb diff --git a/day_15.rb b/day_15.rb new file mode 100644 index 0000000..4331ba0 --- /dev/null +++ b/day_15.rb @@ -0,0 +1,27 @@ +regex = /(\w+): capacity (-?\d+), durability (\d+), flavor (-?\d+), texture (-?\d+), calories (\d+)/ +ingredients = Hash[DATA.read.scan(regex).map {|name, *attrs| [name, attrs.map(&:to_i)] }] +# ingredients = {"Butterscotch" => [-1, -2, 6, 3, 8], +# "Cinnamon" => [2, 3, -2, -1, 3]} +max = 0 +(0..100).each do |i| + (0..100-i).each do |j| + (0..100-i-j).each do |k| + l = 100-i-j-k + a = [i,j,k,l] + s = (0..3).map {|s| + ingredients.values.map {|x| x[s] }.zip(a).map {|x,y| x*y }.inject(:+) + }.map {|s| + [s,0].max + }.inject(:*) + if s > max && + max = s + p a, s + end + end + end +end +__END__ +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