Solved Day 17
parent
dd8e417037
commit
1e05c90239
|
@ -0,0 +1,20 @@
|
|||
50
|
||||
44
|
||||
11
|
||||
49
|
||||
42
|
||||
46
|
||||
18
|
||||
32
|
||||
26
|
||||
40
|
||||
21
|
||||
7
|
||||
18
|
||||
43
|
||||
10
|
||||
47
|
||||
36
|
||||
24
|
||||
22
|
||||
40
|
|
@ -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}"
|
Loading…
Reference in New Issue