Solved Day 17

main
s00ner 2022-07-19 15:11:25 -04:00
parent dd8e417037
commit 1e05c90239
2 changed files with 50 additions and 0 deletions

20
day17/input Normal file
View File

@ -0,0 +1,20 @@
50
44
11
49
42
46
18
32
26
40
21
7
18
43
10
47
36
24
22
40

30
day17/solution.rb Normal file
View File

@ -0,0 +1,30 @@
#!/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}"