diff --git a/2023/day05/src/part2.py b/2023/day05/src/part2.py index 73884b5..ec15d1e 100644 --- a/2023/day05/src/part2.py +++ b/2023/day05/src/part2.py @@ -6,6 +6,7 @@ text: str = open("input.txt", "r").read() _value: int = 0 _lines = text.splitlines() +CHUNK_SIZE = 100000000 current_ranges = [] convertions = [] @@ -39,7 +40,6 @@ for i, line in enumerate(_lines): if (line.endswith(" map:")): convertions.append(extract_map_data(_lines[i + 1:])) - current_time = time.time() def display_duration(interval_between_call, nb_total_values): global current_time @@ -57,6 +57,8 @@ 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) % 1000000 == 0): + print(f"{int((i - start)/(stop - start))}% ({i - start}/{stop - start})") value = do_all_convertions(lst_conversions, i) #print(min_value, value, min(value, min_value)) min_value = min(value, min_value) @@ -69,7 +71,6 @@ def thread_process(convertions, start_value, chunk): global values values.append(get_min_in_range(convertions, start_value, chunk)) -CHUNK_SIZE = 10000000 for current_range in current_ranges: print("new range") start, stop = current_range @@ -86,12 +87,13 @@ for current_range in current_ranges: while (i < len(chunks)): t = threading.Thread(target=thread_process, args=(convertions, start_value, chunks[i])) t.start() - print(f"start thread{i}/{len(chunks) - 1}") + print(f"start thread{i + 1}/{len(chunks)}") i += 1 start_value = chunks[i - 1] -while (True): - print(len(values)) +while (threading.active_count() != 1): + print(values, threading.active_count() - 1) + time.sleep(10) _value = min(values)