add: day05: part2 pls never read this code pls pls
This commit is contained in:
49
2025/day05/part2.py
Normal file
49
2025/day05/part2.py
Normal file
@ -0,0 +1,49 @@
|
||||
text: str
|
||||
|
||||
with open("input.txt") as f:
|
||||
text = f.read()
|
||||
|
||||
total: int = 0
|
||||
|
||||
|
||||
ranges_str, dates = text.split("\n\n")
|
||||
|
||||
ranges: list[list[int, int]] = []
|
||||
for range_str in ranges_str.splitlines():
|
||||
start, stop = range_str.split("-")
|
||||
ranges.append([int(start), int(stop)])
|
||||
|
||||
range_wo_overlap: list[list[int, int]] = []
|
||||
|
||||
bozo2 = 1
|
||||
bozo = True
|
||||
while bozo:
|
||||
bozo = False
|
||||
range_wo_overlap: list[list[int, int]] = []
|
||||
for start, stop in ranges[::bozo2]:
|
||||
placed: bool = False
|
||||
for i, value in enumerate(range_wo_overlap):
|
||||
start2, stop2 = value
|
||||
if (start2 <= start <= stop2):
|
||||
if (stop > stop2):
|
||||
range_wo_overlap[i][1] = stop
|
||||
bozo = True
|
||||
placed = True
|
||||
break
|
||||
if (start2 <= stop <= stop2):
|
||||
if (start < start2):
|
||||
range_wo_overlap[i][0] = start
|
||||
bozo = True
|
||||
placed = True
|
||||
break
|
||||
if not placed:
|
||||
range_wo_overlap.append([start, stop])
|
||||
ranges = range_wo_overlap
|
||||
bozo2 *= -1
|
||||
|
||||
print(ranges)
|
||||
|
||||
for start, stop in ranges:
|
||||
total += stop - start + 1
|
||||
|
||||
print(total)
|
||||
Reference in New Issue
Block a user