points = 0 def contains(ran1, ran2): return ran1.start <= ran2.start and ran1.stop >= ran2.stop def overlap(ran1, ran2): return ran1.stop >= ran2.start and ran1.start <= ran2.stop #with open("example") as f: with open("input") as f: lines = f.readlines() for line in lines: r1, r2 = line.strip().split(",") r11, r12 = list(map(int, r1.split("-"))) r21, r22 = list(map(int, r2.split("-"))) ran1, ran2 = range(r11, r12), range(r21, r22) if overlap(ran1, ran2): points += 1 print(points)