37 lines
795 B
Python
37 lines
795 B
Python
from aoc.input import get_input
|
|
from aoc.partselector import part_one, part_two
|
|
|
|
def pw(line):
|
|
pol, pw = line.split(': ')
|
|
polcnt, l = pol.split(' ')
|
|
a, b = map(int,polcnt.split('-'))
|
|
return a, b, l, pw
|
|
|
|
inp = get_input(pw)
|
|
|
|
|
|
if part_one():
|
|
corrent = 0
|
|
for a, b, l, pw in inp:
|
|
count = 0
|
|
for i in pw:
|
|
if i == l:
|
|
count += 1
|
|
if count >= a and count <= b:
|
|
corrent += 1
|
|
print (corrent)
|
|
|
|
|
|
if part_two():
|
|
corrent = 0
|
|
for a, b, l, pw in inp:
|
|
count = 0
|
|
for z, i in enumerate(pw, start=1):
|
|
if z == a:
|
|
correct = i == l
|
|
if z == b:
|
|
correct = (bool(correct) != bool(i==l))
|
|
if correct:
|
|
corrent += 1
|
|
print (corrent)
|