From e7db1a225138b5caea5cb00aff39e82a69503999 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Fri, 25 Dec 2015 17:48:49 -0800 Subject: [PATCH] Day 24.0 --- ruby/day_24.rb | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 ruby/day_24.rb diff --git a/ruby/day_24.rb b/ruby/day_24.rb new file mode 100644 index 0000000..14501a0 --- /dev/null +++ b/ruby/day_24.rb @@ -0,0 +1,43 @@ +require "letters" + +packages = DATA.read.split("\n").map(&:to_i) +total = packages.inject(:+) +weight = total/3 + +(1..packages.size).each do |i| + puts i + groups = packages.combination(i).select {|combo| combo.inject(:+) == weight } + unless groups.empty? + p groups.map {|g| g.inject(:*) }.sort[0,10] + exit + end +end +__END__ +1 +3 +5 +11 +13 +17 +19 +23 +29 +31 +37 +41 +43 +47 +53 +59 +67 +71 +73 +79 +83 +89 +97 +101 +103 +107 +109 +113