split code to prepare multi thread
This commit is contained in:
parent
26bf8f179a
commit
9c79eaa6cf
@ -1,3 +1,6 @@
|
||||
import threading
|
||||
import time
|
||||
|
||||
text: str = open("input.txt", "r").read()
|
||||
|
||||
_value: int = 0
|
||||
@ -38,9 +41,6 @@ for i, line in enumerate(_lines):
|
||||
if (line.endswith(" map:")):
|
||||
convertions.append(extract_map_data(_lines[i + 1:]))
|
||||
|
||||
print(convertions)
|
||||
|
||||
import time
|
||||
|
||||
current_time = time.time()
|
||||
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)
|
||||
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:
|
||||
start, stop = bozo
|
||||
while (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
|
||||
_min = get_min_in_range(convertions, start, stop)
|
||||
|
||||
_value = _min
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user