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

20 lines
456 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]
min_occurence, max_occurence = rule.split('-')
min_occurence = int(min_occurence)
max_occurence = int(max_occurence)
is_valid = min_occurence <= password.count(char) <= max_occurence
if is_valid:
COUNT += 1
print(COUNT)