Resolve day 2

main
Guillaume Dott 2021-11-22 09:28:11 +01:00
parent a0754de631
commit a43593bbcd
2 changed files with 1024 additions and 0 deletions

1000
2/input 100644

File diff suppressed because it is too large Load Diff

24
2/script.rb 100755
View File

@ -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