28 lines
668 B
Python
28 lines
668 B
Python
import aoclib
|
|
import re
|
|
|
|
if 'TEST' not in globals():
|
|
TEST = False
|
|
|
|
my_input = aoclib.getInputLineAsArray(day=2, test=TEST)
|
|
splitter = re.compile(r'([0-9]+)-([0-9]+) ([a-z]): (.*)')
|
|
|
|
|
|
def getCharacterCount(password, character):
|
|
count = 0
|
|
for char in password:
|
|
if char == character:
|
|
count = count + 1
|
|
|
|
return count
|
|
|
|
|
|
valid_count = 0
|
|
for line in my_input:
|
|
match = re.match(splitter, line)
|
|
(min_count, max_count, character, password) = match.group(1, 2, 3, 4)
|
|
if int(min_count) <= getCharacterCount(password, character) <= int(max_count):
|
|
valid_count = valid_count + 1
|
|
|
|
aoclib.printSolution(2, 1, valid_count, TEST)
|