require 'set' @input = File.read("4.input").split("\n") def set_from_range(range) (from, to) = range.split("-") return Set.new((from.to_i..to.to_i).to_a) end score_1 = 0 score_2 = 0 @input.each do |line| (left, right) = line.split(",") left = set_from_range(left) right = set_from_range(right) if left.subset?(right) or right.subset?(left) then score_1 += 1 end if left.intersect?(right) then score_2 += 1 end end puts score_1 puts score_2