adventofcode-2020/02/solve01.py

22 lines
424 B
Python
Raw Normal View History

2021-12-13 21:12:22 +01:00
#!/usr/bin/env python
import re
RE_LINE = re.compile("^(\d+)-(\d+)\s+(.):\s+(.*)$")
valid = 0
with open("input01.txt","r") as f:
for line in f:
m = RE_LINE.match(line.strip())
if not m:
print(line)
continue
(pmin, pmax) = (int(m.group(1)), int(m.group(2)))
(pch, pline) = (m.group(3), m.group(4))
if pline.count(pch) < pmin:
continue
if pline.count(pch) > pmax:
continue
valid +=1
print(valid)