1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
class Range def overlap?(other) cover?(other.first) || other.cover?(first) end end pairs = $stdin.readlines.map { |line| line.strip.split(?,).map { |range| Range.new(*range.split(?-).map(&:to_i)) } } puts pairs.select { |a, b| a.overlap?(b) }.count