added day 02

This commit is contained in:
Peter Hudec 2021-12-13 21:12:22 +01:00
parent da5530cdef
commit ebb709b4cf
4 changed files with 1045 additions and 0 deletions

1000
02/input01.txt Normal file

File diff suppressed because it is too large Load Diff

3
02/input01_sample.txt Normal file
View File

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

22
02/solve01.py Normal file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env python
import re
RE_LINE = re.compile("^(\d+)-(\d+)\s+(.):\s+(.*)$")
valid = 0
with open("input01.txt","r") as f:
for line in f:
m = RE_LINE.match(line.strip())
if not m:
print(line)
continue
(pmin, pmax) = (int(m.group(1)), int(m.group(2)))
(pch, pline) = (m.group(3), m.group(4))
if pline.count(pch) < pmin:
continue
if pline.count(pch) > pmax:
continue
valid +=1
print(valid)

20
02/solve02.py Normal file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env python
import re
RE_LINE = re.compile("^(\d+)-(\d+)\s+(.):\s+(.*)$")
valid = 0
with open("input01.txt","r") as f:
for line in f:
m = RE_LINE.match(line.strip())
if not m:
print(line)
continue
(pmin, pmax) = (int(m.group(1)), int(m.group(2)))
(pch, pline) = (m.group(3), m.group(4))
tmp = pline[pmin-1] + pline[pmax-1]
if tmp.count(pch) == 1:
valid +=1
print(valid)