24 lines
656 B
Python
24 lines
656 B
Python
with open('input') as f:
|
|
data = [line.strip().split(' ') for line in f]
|
|
|
|
def first_policy(first, second, letter, password):
|
|
return first <= password.count(letter) <= second
|
|
|
|
def second_policy(first, second, letter, password):
|
|
return (password[first - 1] == letter) ^ (password[second - 1] == letter)
|
|
|
|
def analyze(policy):
|
|
result = 0
|
|
for line in data:
|
|
first, second= [int(i) for i in line[0].split('-')]
|
|
letter = line[1].replace(':', '')
|
|
password = line[2]
|
|
|
|
if policy(first, second, letter, password):
|
|
result += 1
|
|
|
|
return result
|
|
|
|
print(analyze(first_policy))
|
|
print(analyze(second_policy))
|