summaryrefslogtreecommitdiffstats
path: root/4.py
blob: 3279e7ea2d65ad7f1dfc7e50d91df1c883c976f2 (plain)
1
2
3
4
5
6
7
8
9
with open('4.in') as f:
    inp = [tuple(tuple(map(int, elf.split('-'))) for elf in line.rstrip().split(',')) for line in f]
def fully_contains(a, b):
    return  b[0] >= a[0] and b[1] <= a[1] or a[0] >= b[0] and a[1] <= b[1]
def overlaps(a, b):
    return b[0] <= a[0] <= b[1] or b[0] <= a[1] <= b[1] or \
            a[0] <= b[0] <= a[1] # or a[0] <= b[1] <= a[1]
print(sum(fully_contains(a, b) for a, b in inp))
print(sum(overlaps(a, b) for a, b in inp))