Solve 2020/02
parent
0eedce18fc
commit
559f49ac56
File diff suppressed because it is too large
Load Diff
@ -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)
|
@ -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)
|
Loading…
Reference in New Issue