#/usr/bin/env python import re RE_MATCH = re.compile(r"^(\d+)\-(\d+),(\d+)\-(\d+)$") total = 0 with open("input.txt", "r") as f: for line in f: line = line.strip() m = RE_MATCH.match(line) l1 = set(list(range(int(m.group(1)),int(m.group(2))+1))) l2 = set(list(range(int(m.group(3)),int(m.group(4))+1))) l = l2.intersection(l1) if (l == l1) or (l == l2): total += 1 print(total)