aoc/2020/02/02_re.py
2020-12-10 17:11:17 -06:00

8 lines
340 B
Python

import re
with open("input.txt", "r") as f:
regex = re.compile(r'(\d+)-(\d+) (\w): (\w+)')
passwords = [regex.match(x).groups() for x in f]
part1 = sum([int(a) <= w.count(c) <= int(b) for (a,b,c,w) in passwords])
print(f'{part1=}')
part2 = sum([ (c == w[int(a)-1]) != (c == w[int(b)-1]) for (a,b,c,w) in passwords])
print(f'{part2=}')