Resolve day 2
parent
a0754de631
commit
a43593bbcd
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require_relative '../common'
|
||||
|
||||
def part1
|
||||
Input.new(__dir__).readlines.map do |gift|
|
||||
l, w, h = gift.split('x').map(&:to_i)
|
||||
areas = [l * w, w * h, h * l]
|
||||
|
||||
areas.map { |area| area * 2 }.sum + areas.min
|
||||
end.sum
|
||||
end
|
||||
|
||||
def part2
|
||||
Input.new(__dir__).readlines.map do |gift|
|
||||
dimensions = gift.split('x').map(&:to_i)
|
||||
dimensions.sort[0, 2].sum * 2 + dimensions.inject(:*)
|
||||
end.sum
|
||||
end
|
||||
|
||||
puts "=== Part 1 ==="
|
||||
puts part1
|
||||
puts "=== Part 2 ==="
|
||||
puts part2
|
Loading…
Reference in New Issue