2020aoc/day2.py

33 lines
766 B
Python

pw_db = []
with open('day2/input') as reader:
for l in reader.readlines():
s = l.split()
split_restriction = s[0].index("-")
restriction_min = int(s[0][:split_restriction])
restriction_max = int(s[0][split_restriction+1:])
c = s[1][:-1]
p = s[2]
pw_db.append(((restriction_min, restriction_max), c, p))
valids = 0
for pw in pw_db:
count = pw[2].count(pw[1])
if pw[0][0] <= count <= pw[0][1]:
valids += 1
print(valids)
valids2 = 0
for pw in pw_db:
first = pw[0][0]
second = pw[0][1]
c = pw[1]
p = pw[2]
l = len(p)
if (first <= l and p[first-1] == c) is not (second <= l and p[second-1] == c):
valids2 += 1
print(valids2)