25 lines
487 B
Ruby
Executable File
25 lines
487 B
Ruby
Executable File
#!/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
|