This commit is contained in:
Peter Hudec 2022-12-04 12:56:23 +01:00
parent da38a63b74
commit 1345643542
4 changed files with 1044 additions and 0 deletions

1000
04/input.txt Normal file

File diff suppressed because it is too large Load Diff

6
04/input_sample.txt Normal file
View 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
View 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
View 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)