fix: get the min value of all ranges

This commit is contained in:
starnakin 2023-12-05 10:15:20 +01:00
parent 9c79eaa6cf
commit 618324bb17

View File

@ -1,20 +1,20 @@
import threading
import time
text: str = open("input.txt", "r").read()
text: str = open("example.txt", "r").read()
_value: int = 0
_lines = text.splitlines()
current_range = []
current_ranges = []
convertions = []
bozo = _lines[0][7:].split(" ")
for i, value in enumerate(bozo):
if (i % 2):
continue
current_range.append((int(bozo[i]), int(bozo[i]) + int(bozo[i + 1])))
current_ranges.append((int(bozo[i]), int(bozo[i]) + int(bozo[i + 1])))
def extract_map_data(lines: [str]):
lst = []
@ -35,8 +35,6 @@ def translation(lst: list[dict], value: int):
break
return value
_min = None
for i, line in enumerate(_lines):
if (line.endswith(" map:")):
convertions.append(extract_map_data(_lines[i + 1:]))
@ -65,13 +63,15 @@ def get_min_in_range(lst_conversions, start, stop):
print(i - start, '/', stop - start)
value = do_all_convertions(lst_conversions, i)
min_value = min(min_value, value)
print(min_value, value, min(value, min_value))
min_value = min(value, min_value)
i += 1
return (min_value)
for bozo in current_range:
start, stop = bozo
_min = get_min_in_range(convertions, start, stop)
_min = 2000000000000000000
for current_range in current_ranges:
start, stop = current_range
_min = min(_min, get_min_in_range(convertions, start, stop))
_value = _min