31 lines
628 B
Ruby
31 lines
628 B
Ruby
#!/bin/env ruby
|
|
require 'pry'
|
|
|
|
input = File.readlines('./input').map(&:to_i)
|
|
testing = [20, 15, 10, 5, 5]
|
|
|
|
containers = testing
|
|
liters = 25
|
|
|
|
containers = input
|
|
liters = 150
|
|
|
|
solutions = []
|
|
|
|
1.upto(containers.count) do |i|
|
|
sets = containers.combination(i).select do |combo|
|
|
combo.sum == liters
|
|
end
|
|
solutions.concat(sets)
|
|
end
|
|
|
|
puts "Part 1 Solution: #{solutions.count}"
|
|
# binding.pry
|
|
|
|
# Part 2
|
|
|
|
min_containers = solutions.reduce { |memo, set| set.count < memo.count ? set : memo }.count
|
|
min_containers_count = solutions.select { |set| set.count == min_containers }.count
|
|
|
|
puts "Part 2 Solution: #{min_containers_count}"
|