adventofcode/2020/2/solve.py

18 lines
413 B
Python
Raw Normal View History

2022-12-01 21:13:55 +01:00
#!/usr/bin/env python3
import re
pattern = re.compile('(\d+)-(\d+)\s(\w):\s(\w+)')
with open('input', 'r') as f:
content = list(map(str.strip, f.readlines()))
valid_pws = 0
for entry in content:
mini, maxi, char, pw = re.match(pattern, entry).groups(1)
mini = int(mini)
maxi = int(maxi)
char_count = pw.count(char)
if mini <= char_count <= maxi:
valid_pws += 1
print(valid_pws)