Files
advent-of-code/2025/day05/part2.py

73 lines
2.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

range_list: list[list:[str]] = [['1','5'],['7','8']]
items_list: list[int] = [1,2,3,6,16]
valid_id: list[int] = []
final_range: list[list:[int]] = [[0,0]]
input = """3-6
5-5
10-14
16-20
12-18
1
5
8
11
17
32"""
# input = """515109478873629-517495683097941
# 55910578479451-59894189259887
# 388889831860114-389361546156805
# 426667061525753-431247335780190
# 163539375204061
# 531903863069312
# 34101977519160
# 164401920447043
# 5765415079155
# 235541805889895
# 241438782449974
# 228538610394597
# 557824039518207"""
# with open("input.txt", "r") as file:
# input = file.read()
range_list = list(map(list, [row.split("-") for row in input.split("\n\n")[0].strip().split("\n")]))
items_list = list(map(int, input.split("\n\n")[1].strip().split("\n")))
# получаем все возможные не "протухшие" id продуктов
# for index,i in enumerate(items_list):
# for element in range_list:
# if i >= int(element[0]) and i <= int(element[1]):
# valid_id.append(i)
low_list, high_list = [], []
for item in range_list:
low_list.append(int(item[0]))
high_list.append(int(item[1]))
range_new_dict: dict[int:int] = {}
for low,high in zip(low_list, high_list):
range_new_dict[int(high)] = int(low)
high_list = sorted(high_list, reverse=True)
final_range = [[0,high_list[0]]]
for d in high_list:
if d >= final_range[-1][0] and d != range_new_dict[d]:
final_range[-1][0]= range_new_dict[d]
final_range[-1][1]= final_range[-1][1]
print("занесли изменения")
# elif d == range_new_dict[d] and final_range[-1][1] < d:
if d > final_range[-1][0] and d == range_new_dict[d]:
print("pass!!!")
pass
else:
print("bang!")
final_range.append([range_new_dict[d],d])
result: int = 0
for item in final_range:
print(item)
result += item[1] - item[0] + 1
# print(result)
print("result",result)
# print("Всего найденно",len(set(valid_id)))