This commit is contained in:
Stefan Harmuth 2020-12-02 09:17:39 +01:00
parent 6348ae58a3
commit 5f1e68270b
5 changed files with 1052 additions and 3 deletions

27
day02.py Normal file
View File

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

19
day02_2.py Normal file
View File

@ -0,0 +1,19 @@
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]): (.*)')
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 (password[int(min_count) - 1] == character or password[int(max_count) - 1] == character) \
and password[int(min_count) - 1] != password[int(max_count) - 1]:
valid_count = valid_count + 1
aoclib.printSolution(2, 1, valid_count, TEST)

1000
inputs/2 Normal file

File diff suppressed because it is too large Load Diff

3
inputs/2_test Normal file
View File

@ -0,0 +1,3 @@
1-3 a: abcde
1-3 b: cdefg
2-9 c: ccccccccc

View File

@ -22,7 +22,7 @@ for _, _, files in os.walk(aoclib.BASE_PATH):
if flags.test: if flags.test:
TEST = True TEST = True
exec(open(f).read()) exec(open(f).read())
else:
TEST = False TEST = False
exec(open(f).read()) exec(open(f).read())