Files
advent-of-code/2022/04/part2
2022-12-04 18:03:18 +00:00

21 lines
390 B
Python
Executable File

#!/usr/bin/env python
def build_range(text):
first, last = text.split("-")
return range(int(first), int(last)+1)
count = 0
with open('input') as f:
for line in f:
aS, bS = line.rstrip().split(",")
a = build_range(aS)
b = build_range(bS)
if (a[0] in b or a[-1] in b) or (b[0] in a or b[-1] in a):
count = count + 1
print(count)