Solved Day 2
parent
def5de316d
commit
77a6417a3c
File diff suppressed because it is too large
Load Diff
|
@ -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
|
Loading…
Reference in New Issue