Solve 2020/02

This commit is contained in:
Alfred Melch 2020-12-02 07:59:36 +01:00
parent 0eedce18fc
commit 559f49ac56
3 changed files with 1038 additions and 0 deletions

1000
2020/02/input Normal file

File diff suppressed because it is too large Load Diff

19
2020/02/solution1.py Normal file
View File

@ -0,0 +1,19 @@
"""
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)

19
2020/02/solution2.py Normal file
View File

@ -0,0 +1,19 @@
"""
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)