added day 02
This commit is contained in:
parent
da5530cdef
commit
ebb709b4cf
1000
02/input01.txt
Normal file
1000
02/input01.txt
Normal file
File diff suppressed because it is too large
Load Diff
3
02/input01_sample.txt
Normal file
3
02/input01_sample.txt
Normal file
@ -0,0 +1,3 @@
|
||||
1-3 a: abcde
|
||||
1-3 b: cdefg
|
||||
2-9 c: ccccccccc
|
22
02/solve01.py
Normal file
22
02/solve01.py
Normal 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
20
02/solve02.py
Normal 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)
|
Loading…
x
Reference in New Issue
Block a user