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