2022/04/script.rb

25 lines
661 B
Ruby
Raw Normal View History

2022-12-06 11:59:50 +01:00
#!/usr/bin/env ruby
require_relative '../common'
class Day04 < Day
def part1
stdin.map do |pair|
pair.split(',').map { |elve| first, last = elve.split('-'); first.to_i..last.to_i }
end.select do |pair|
pair.first.cover?(pair.last) || pair.last.cover?(pair.first)
end.size
end
def part2
stdin.map do |pair|
pair.split(',').map { |elve| first, last = elve.split('-'); first.to_i..last.to_i }
end.select do |pair|
pair.first.include?(pair.last.first) || pair.first.include?(pair.last.last) ||
pair.last.include?(pair.first.first) || pair.last.include?(pair.first.last)
end.size
end
end
Day04.run