Primeros 2 dias de advent of code :3

This commit is contained in:
Daniel Cortés
2020-12-02 06:04:36 -03:00
commit 145c688999
7 changed files with 1337 additions and 0 deletions

View File

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