25 lines
661 B
Ruby
25 lines
661 B
Ruby
|
#!/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
|