aoc2020/02/2.py

7 lines
344 B
Python
Raw Normal View History

2020-12-02 19:15:34 +00:00
lines = open("input", "r").read().split("\n")
import re
matches = [re.match(r"^([0-9]+)-([0-9]+) ([a-z]): ([a-z]+)$", line) for line in lines]
matches = [m for m in matches if m is not None]
valids = [True for m in matches if (m.group(4)[int(m.group(1)) - 1] == m.group(3)) ^ (m.group(4)[int(m.group(2)) - 1] == m.group(3))]
print(len(valids))