recreation of part1
This commit is contained in:
parent
23a9d663e4
commit
8ced78338c
@ -4,39 +4,25 @@ _value: int = 0
|
|||||||
|
|
||||||
lines = text.splitlines()
|
lines = text.splitlines()
|
||||||
|
|
||||||
current_values = []
|
values = []
|
||||||
next_convertion = {}
|
next_convertion = {}
|
||||||
|
|
||||||
for value in lines[0][7:].split(" "):
|
values = list(map(int, lines[0][7:].split()))
|
||||||
current_values.append(int(value))
|
|
||||||
|
|
||||||
def extract_map_data(lines: [str]):
|
print(values)
|
||||||
lst = []
|
|
||||||
for line in lines:
|
|
||||||
if (line == ""):
|
|
||||||
break
|
|
||||||
bozo = line.split()
|
|
||||||
length = int(bozo[2])
|
|
||||||
destination = int(bozo[0]) - int(bozo[1])
|
|
||||||
source_range_start = range(int(bozo[1]), int(bozo[1]) + length)
|
|
||||||
lst.append({"destination": destination, "source_range_start": source_range_start})
|
|
||||||
return lst
|
|
||||||
|
|
||||||
def translation(lst: list[dict], value: int):
|
for conversions in text.split("\n\n")[1:]:
|
||||||
for map in lst:
|
|
||||||
if value in map["source_range_start"]:
|
|
||||||
value += map["destination"]
|
|
||||||
break
|
|
||||||
return value
|
|
||||||
|
|
||||||
lines = lines[2:]
|
_conversion = []
|
||||||
for i, line in enumerate(lines):
|
for conversion in conversions.splitlines()[1:]:
|
||||||
lst = []
|
_conversion.append(list(map(int, conversion.split())))
|
||||||
if (line.endswith(" map:")):
|
|
||||||
lst = extract_map_data(lines[i + 1:])
|
|
||||||
for j, value in enumerate(current_values):
|
|
||||||
current_values[j] = translation(lst, value)
|
|
||||||
|
|
||||||
_value = min(current_values)
|
for i, value in enumerate(values):
|
||||||
|
for dst, src, length in _conversion:
|
||||||
|
if (src <= value <= src + length):
|
||||||
|
values[i] = value + dst - src
|
||||||
|
break;
|
||||||
|
|
||||||
|
_value = min(values)
|
||||||
|
|
||||||
print(_value)
|
print(_value)
|
Loading…
Reference in New Issue
Block a user