generated from public/aoc_template
33 lines
796 B
Python
33 lines
796 B
Python
my_input = open("inputs/input3", "r").read().splitlines()
|
|
|
|
p1 = 0
|
|
p2 = 0
|
|
p3 = 0
|
|
last_boxes = set()
|
|
for line in my_input:
|
|
left, right = line.split(" ")
|
|
l_low, l_high = map(int, left.split("-"))
|
|
r_low, r_high = map(int, right.split("-"))
|
|
p1 += l_high - l_low + 1
|
|
p1 += r_high - r_low + 1
|
|
|
|
if r_low < l_low:
|
|
l_low, l_high, r_low, r_high = r_low, r_high, l_low, l_high
|
|
|
|
if l_high < r_low:
|
|
this_box_set = set(range(l_low, l_high + 1))
|
|
this_box_set |= set(range(r_low, r_high + 1))
|
|
else:
|
|
this_box_set = set(range(min(l_low, r_low), max(l_high, r_high) + 1))
|
|
|
|
p2 += len(this_box_set)
|
|
if len(this_box_set | last_boxes) > p3:
|
|
p3 = len(this_box_set | last_boxes)
|
|
|
|
last_boxes = this_box_set
|
|
|
|
print(p1)
|
|
print(p2)
|
|
print(p3)
|
|
|