advent-of-code/2020/02/solution2.py

20 lines
415 B
Python
Raw Normal View History

2020-12-02 07:59:36 +01:00
"""
Solution to 2020/01
"""
COUNT = 0
with open('input', 'r') as file:
for line in file.readlines():
rule, char, password = line.strip().split()
char = char[0]
pos_1, pos_2 = rule.split('-')
pos_1 = int(pos_1) - 1
pos_2 = int(pos_2) - 1
is_valid = (password[pos_1] == char) ^ (password[pos_2] == char)
if is_valid:
COUNT += 1
print(COUNT)