|
|
@ -3,14 +3,41 @@ seeds = [int(i) for i in data[0][7:].split()] |
|
|
|
maps = [[[int(i) for i in numb.split()] for numb in block.splitlines()[1:]] for block in data[1:]] |
|
|
|
maps = [[[int(i) for i in numb.split()] for numb in block.splitlines()[1:]] for block in data[1:]] |
|
|
|
#[destinationStart, sourceStart, length] |
|
|
|
#[destinationStart, sourceStart, length] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
seeds2 = [] |
|
|
|
|
|
|
|
#[(start, end)] |
|
|
|
|
|
|
|
for i in range(0, len(seeds), 2): |
|
|
|
|
|
|
|
seeds2.append((seeds[i], seeds[i]+seeds[i+1]-1)) |
|
|
|
|
|
|
|
|
|
|
|
for m in maps: |
|
|
|
for m in maps: |
|
|
|
newSeeds = list(seeds) |
|
|
|
newSeeds = list(seeds) |
|
|
|
for line in m: |
|
|
|
newSeeds2 = list() |
|
|
|
target, source, length = line |
|
|
|
for target, source, length in m: |
|
|
|
for i in range(len(seeds)): |
|
|
|
for i in range(len(seeds)): |
|
|
|
seed = seeds[i] |
|
|
|
seed = seeds[i] |
|
|
|
if seed in range(source, source+length): |
|
|
|
if seed in range(source, source+length): |
|
|
|
newSeeds[i] = seed + (target - source) |
|
|
|
newSeeds[i] = seed + (target - source) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while seeds2: |
|
|
|
|
|
|
|
rangeStart, rangeEnd = seeds2.pop() |
|
|
|
|
|
|
|
for r, mapStart, length in m: |
|
|
|
|
|
|
|
mapEnd = mapStart + length -1 |
|
|
|
|
|
|
|
delta = r - mapStart |
|
|
|
|
|
|
|
if mapEnd < rangeStart or mapStart > rangeEnd: |
|
|
|
|
|
|
|
continue |
|
|
|
|
|
|
|
if rangeStart < mapStart: |
|
|
|
|
|
|
|
seeds2.append((rangeStart, mapStart - 1)) |
|
|
|
|
|
|
|
rangeStart = mapStart |
|
|
|
|
|
|
|
if rangeStart < mapStart: |
|
|
|
|
|
|
|
seeds2.append((rangeStart, mapStart - 1)) |
|
|
|
|
|
|
|
rangeStart = mapStart |
|
|
|
|
|
|
|
newSeeds2.append((rangeStart + delta, rangeEnd + delta)) |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
newSeeds2.append((rangeStart, rangeEnd)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
seeds = newSeeds |
|
|
|
seeds = newSeeds |
|
|
|
|
|
|
|
seeds2 = newSeeds2 |
|
|
|
|
|
|
|
|
|
|
|
print(min(newSeeds)) |
|
|
|
print(min(newSeeds)) |
|
|
|
|
|
|
|
print(min(seeds2)[0]) |