Files
python-aoc-2020/day02/part2.py
Sebastian Seedorf 573ac58519 Day 2 (better xor)
2020-12-02 08:38:19 +01:00

15 lines
377 B
Python

import re
#2-5 m: mfvxmmm
regex = re.compile(r'(\d+)-(\d+) (\w): (\w+)', re.I)
items = (re.match(regex, x).groups() for x in open("input.txt"))
items = map(lambda x: [int(x[0]), int(x[1]), *x[2:]], items)
def in_range(lower, upper, char, string):
return (string[lower-1] == char) != (string[upper-1] == char)
count = sum(1 for x in items if in_range(*x))
print(count)