with open('input4.txt','r') as f: inp = f.read().splitlines(keepends=False) score = 0 score1 = 0 for i in inp: tempa, tempb = i.split(',') a1, a2 = map(int, tempa.split('-')) b1, b2 = map(int, tempb.split('-')) if a1 <= b1: if a2 >= b2: score1 += 1 elif b1 <= a1: if b2 >= a2: score1 += 1 elif b1 <= a2: if b2 >= a2: score1 += 1 for i in inp: tempa, tempb = i.split(',') a1, a2 = map(int, tempa.split('-')) b1, b2 = map(int, tempb.split('-')) if b1 <= a1 and a1 <= b2: score += 1 elif b1 <= a2 and a2 <= b2: score += 1 elif a1 <= b1 and b1 <= a2: score += 1 elif a1 <= b2 and b2 <= a2: score += 1 print('Part1', score1) print('Part2', score)