AoC2015/day02/solution.rb

23 lines
637 B
Ruby
Raw Normal View History

2022-07-12 16:41:03 +00:00
#!/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