From 1e05c902391f0cd91b9a08958138117fad90cbc9 Mon Sep 17 00:00:00 2001 From: s00ner Date: Tue, 19 Jul 2022 15:11:25 -0400 Subject: [PATCH] Solved Day 17 --- day17/input | 20 ++++++++++++++++++++ day17/solution.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 day17/input create mode 100644 day17/solution.rb diff --git a/day17/input b/day17/input new file mode 100644 index 0000000..588b253 --- /dev/null +++ b/day17/input @@ -0,0 +1,20 @@ +50 +44 +11 +49 +42 +46 +18 +32 +26 +40 +21 +7 +18 +43 +10 +47 +36 +24 +22 +40 diff --git a/day17/solution.rb b/day17/solution.rb new file mode 100644 index 0000000..f3911eb --- /dev/null +++ b/day17/solution.rb @@ -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}"