adventofcode-2022/04/solve02.py

19 lines
446 B
Python
Raw Normal View History

2022-12-04 12:56:23 +01:00
#/usr/bin/env python
import re
RE_MATCH = re.compile(r"^(\d+)\-(\d+),(\d+)\-(\d+)$")
total = 0
with open("input.txt", "r") as f:
for line in f:
line = line.strip()
m = RE_MATCH.match(line)
l1 = set(list(range(int(m.group(1)),int(m.group(2))+1)))
l2 = set(list(range(int(m.group(3)),int(m.group(4))+1)))
l = l2.intersection(l1)
if len(l):
total += 1
print(total)