From c55c9cf01bb291cacc903e459df27bc2ba338157 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Wed, 16 Dec 2015 21:11:10 -0800 Subject: [PATCH] Day 17.1 --- ruby/day_17.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ruby/day_17.rb b/ruby/day_17.rb index b96335d..215b7a4 100644 --- a/ruby/day_17.rb +++ b/ruby/day_17.rb @@ -1,5 +1,7 @@ buckets = DATA.read.split("\n").map(&:to_i) -puts (1..buckets.size).map {|i| buckets.combination(i).select {|p| p.inject(:+) == 150 }.size }.inject(:+) +combos = (1..buckets.size).flat_map {|i| buckets.combination(i).select {|p| p.inject(:+) == 150 }} +min = combos.map(&:size).min +puts combos.select {|c| c.size == min }.size __END__ 50 44