Complete day 2

This commit is contained in:
Peter J. Holzer 2020-12-12 13:10:55 +01:00 committed by Peter J. Holzer
parent 3d27b97cfe
commit 12e300446b
3 changed files with 1031 additions and 0 deletions

1000
02/input Normal file

File diff suppressed because it is too large Load Diff

15
02/part1 Executable file
View File

@ -0,0 +1,15 @@
#!/usr/bin/python3
import re
valid = 0
with open("input") as fh:
for ln in fh:
m = re.match(r"(\d+)-(\d+) (.): (.*)", ln)
(min, max, char, pw) = m.groups()
min = int(min)
max = int(max)
num = pw.count(char)
valid += min <= num <= max
print(min, max, char, pw, valid)

16
02/part2 Executable file
View File

@ -0,0 +1,16 @@
#!/usr/bin/python3
import re
valid = 0
with open("input") as fh:
for ln in fh:
m = re.match(r"(\d+)-(\d+) (.): (.*)", ln)
(first, second, char, pw) = m.groups()
first = int(first)
second = int(second)
check = pw[first-1] + pw[second-1]
num = check.count(char)
valid += num == 1
print(first, second, char, pw, check, valid)