-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday4.py
41 lines (34 loc) · 1018 Bytes
/
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
import os
from pathlib import Path
the_day = 4
download_data_path = Path("/Users/relyea/Downloads/input.txt")
local_data_path = "/Users/relyea/code/advent_of_code_2022/input"+str(the_day)+".txt"
if download_data_path.exists():
download_data_path.rename(local_data_path)
with open(local_data_path) as input_file:
inpstring = input_file.readlines()
data = [
line.strip()
for line in inpstring
]
# data = open(local_data_path).read().strip().split("\n")
fullycontained = 0
for line in data:
aa,bb = line.split(",")
aa1,aa2 =map(int,aa.split("-"))
bb1,bb2 = map(int,bb.split("-"))
if aa1 >= bb1 and aa2 <= bb2:
fullycontained += 1
elif bb1 >= aa1 and bb2 <= aa2:
fullycontained += 1
print(fullycontained)
overlap = 0
for line in data:
aa,bb = line.split(",")
aa1,aa2 =map(int,aa.split("-"))
bb1,bb2 = map(int,bb.split("-"))
if aa2 >= bb1 and aa1 <= bb2:
overlap += 1
elif bb2 >= aa1 and bb1 <= aa2:
overlap += 1
print(overlap)