blob: 73baa961ce28ee81d23ccc2b80e29b1abe7e73c4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
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)
|