Complete day 2
This commit is contained in:
parent
3d27b97cfe
commit
12e300446b
|
@ -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)
|
||||
|
|
@ -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)
|
||||
|
Loading…
Reference in New Issue