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
426 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:
p1, p2, char, pw = re.match(pattern, entry).groups(1)
p1 = int(p1) - 1
p2 = int(p2) - 1
if pw[p1] == char and pw[p2] != char or pw[p1] != char and pw[p2] == char:
valid_pws += 1
print(valid_pws)