Solved Day 2

main
s00ner 2022-07-12 12:41:03 -04:00
parent def5de316d
commit 77a6417a3c
2 changed files with 1022 additions and 0 deletions

1000
day02/input Normal file

File diff suppressed because it is too large Load Diff

22
day02/solution.rb Normal file
View File

@ -0,0 +1,22 @@
#!/bin/env ruby
require 'pry'
def paper_needed(dimensions)
h, l, w = dimensions
(2 * l * w) + (2 * w * h) + (2 * h * l) + dimensions.min(2).reduce(:*)
end
def ribbon_needed(dimensions)
dimensions.min(2).sum * 2 + dimensions.reduce(:*)
end
presents = File.readlines('./input').map { |line| line.strip.split('x').map(&:to_i) }
# Part 1, How many total square feet of wrapping paper should they order?
paper_total = presents.map { |present| paper_needed(present) }.sum
puts 'Part 1 Solution: ' + paper_total.to_s
ribbon_total = presents.map { |present| ribbon_needed(present) }.sum
puts 'Part 2 Solution: ' + ribbon_total.to_s