Files
advent-of-code/2020/day_2/password_philosophy.py
2020-12-02 06:04:36 -03:00

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