""" 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)