day04
This commit is contained in:
parent
da38a63b74
commit
1345643542
1000
04/input.txt
Normal file
1000
04/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
6
04/input_sample.txt
Normal file
6
04/input_sample.txt
Normal file
@ -0,0 +1,6 @@
|
||||
2-4,6-8
|
||||
2-3,4-5
|
||||
5-7,7-9
|
||||
2-8,3-7
|
||||
6-6,4-6
|
||||
2-6,4-8
|
19
04/solve01.py
Normal file
19
04/solve01.py
Normal file
@ -0,0 +1,19 @@
|
||||
#/usr/bin/env python
|
||||
|
||||
import re
|
||||
|
||||
RE_MATCH = re.compile(r"^(\d+)\-(\d+),(\d+)\-(\d+)$")
|
||||
|
||||
total = 0
|
||||
with open("input.txt", "r") as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
m = RE_MATCH.match(line)
|
||||
|
||||
l1 = set(list(range(int(m.group(1)),int(m.group(2))+1)))
|
||||
l2 = set(list(range(int(m.group(3)),int(m.group(4))+1)))
|
||||
l = l2.intersection(l1)
|
||||
|
||||
if (l == l1) or (l == l2):
|
||||
total += 1
|
||||
print(total)
|
19
04/solve02.py
Normal file
19
04/solve02.py
Normal file
@ -0,0 +1,19 @@
|
||||
#/usr/bin/env python
|
||||
|
||||
import re
|
||||
|
||||
RE_MATCH = re.compile(r"^(\d+)\-(\d+),(\d+)\-(\d+)$")
|
||||
|
||||
total = 0
|
||||
with open("input.txt", "r") as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
m = RE_MATCH.match(line)
|
||||
|
||||
l1 = set(list(range(int(m.group(1)),int(m.group(2))+1)))
|
||||
l2 = set(list(range(int(m.group(3)),int(m.group(4))+1)))
|
||||
l = l2.intersection(l1)
|
||||
|
||||
if len(l):
|
||||
total += 1
|
||||
print(total)
|
Loading…
x
Reference in New Issue
Block a user