From 618324bb179e65a0fe8b6f03810319b8019360dd Mon Sep 17 00:00:00 2001 From: starnakin Date: Tue, 5 Dec 2023 10:15:20 +0100 Subject: [PATCH] fix: get the min value of all ranges --- 2023/day05/src/part2.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/2023/day05/src/part2.py b/2023/day05/src/part2.py index adc2a1b..1cc2f58 100644 --- a/2023/day05/src/part2.py +++ b/2023/day05/src/part2.py @@ -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