Skip to content

Commit 7ffc93f

Browse files
committed
day04
1 parent bf7b1e7 commit 7ffc93f

File tree

4 files changed

+1028
-5
lines changed

4 files changed

+1028
-5
lines changed

2022/04/__init__.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
def cast_input(inputs: str):
2+
return map(
3+
lambda x: map(lambda x: map(int, str(x).split('-')), str(x).split(',')),
4+
inputs.splitlines(),
5+
)
6+
7+
8+
def fully_contains(x):
9+
(al, ar), (bl, br) = x
10+
return al <= bl and br <= ar or al >= bl and br >= ar
11+
12+
13+
def part1(inputs):
14+
return sum(map(fully_contains, inputs))
15+
16+
17+
def overlap(x):
18+
(al, ar), (bl, br) = x
19+
return max(al, bl) <= min(ar, br)
20+
21+
22+
def part2(inputs):
23+
return sum(map(overlap, inputs))

0 commit comments

Comments
 (0)