You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
413 B
Python

2 years ago
#!/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)