-
Notifications
You must be signed in to change notification settings - Fork 0
/
day4.py
60 lines (41 loc) · 1.04 KB
/
day4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import util
import numpy as np
test_data: [str] = \
"""2-4,6-8
2-3,4-5
5-7,7-9
2-8,3-7
6-6,4-6
2-6,4-8"""
def contains(a: str, b: str):
a_s = util.list_as_ints(a.split("-"))
b_s = util.list_as_ints(b.split("-"))
return a_s[0] >= b_s[0] and a_s[1] <= b_s[1]
def task1(input):
total = 0
for pair in input:
vals = util.as_csv(pair)
if contains(vals[0], vals[1]) or contains(vals[1], vals[0]):
total += 1
return total
def task2(input):
total = 0
for pair in input:
vals = util.as_csv(pair)
a_s = util.list_as_ints(vals[0].split("-"))
b_s = util.list_as_ints(vals[1].split("-"))
for a in range(a_s[0], a_s[1] + 1):
if b_s[0] <= a <= b_s[1]:
total += 1
break
return total
def parse(data: str):
return util.as_lines(data)
def main():
data: str = util.get(4, 2022)
# data = test_data
input = parse(data)
print(task1(input))
print(task2(input))
if __name__ == "__main__":
main()