split code to prepare multi thread

This commit is contained in:
starnakin 2023-12-05 10:10:33 +01:00
parent 26bf8f179a
commit 9c79eaa6cf

View File

@ -1,3 +1,6 @@
import threading
import time
text: str = open("input.txt", "r").read() text: str = open("input.txt", "r").read()
_value: int = 0 _value: int = 0
@ -38,9 +41,6 @@ for i, line in enumerate(_lines):
if (line.endswith(" map:")): if (line.endswith(" map:")):
convertions.append(extract_map_data(_lines[i + 1:])) convertions.append(extract_map_data(_lines[i + 1:]))
print(convertions)
import time
current_time = time.time() current_time = time.time()
def display_duration(interval_between_call, nb_total_values): def display_duration(interval_between_call, nb_total_values):
@ -50,23 +50,28 @@ def display_duration(interval_between_call, nb_total_values):
diff = int(((current_time - old_time) / interval_between_call) * nb_total_values) diff = int(((current_time - old_time) / interval_between_call) * nb_total_values)
print(f"{int(diff / 3600)}h {int(diff % 3600 / 60)}min {int(diff % 60)}s") print(f"{int(diff / 3600)}h {int(diff % 3600 / 60)}min {int(diff % 60)}s")
def do_all_convertions(lst_convertions: [[dict]], value):
for i, tab_convertion in enumerate(convertions):
value = translation(tab_convertion, value)
return value
def get_min_in_range(lst_conversions, start, stop):
min_value = do_all_convertions(lst_conversions, start)
i = start + 1;
while (i != stop):
if ((i - start) % 10000 == 0):
display_duration(10000, stop - start)
print(i - start, '/', stop - start)
value = do_all_convertions(lst_conversions, i)
min_value = min(min_value, value)
i += 1
return (min_value)
for bozo in current_range: for bozo in current_range:
start, stop = bozo start, stop = bozo
while (start < stop): _min = get_min_in_range(convertions, start, stop)
if (start % 1000 == 0):
display_duration(1000, stop - start)
print(start, '/', stop)
value = start
for i, tab_convertion in enumerate(convertions):
value = translation(tab_convertion, value)
if (_min == None):
_min = value
else:
_min = min(_min, value)
start += 1
_value = _min _value = _min