aoc/2020/02/02_re.py

8 lines
340 B
Python
Raw Normal View History

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=}')