aoc2023/d05/part2.py

32 lines
885 B
Python
Raw Normal View History

2023-12-06 08:57:38 +00:00
import sys
en=enumerate
L:list[str] = sys.stdin.read().split('\n\n')
L = [l.split(':') for l in L]
L = [l[1].strip().split('\n') for l in L]
L = [list(map(lambda x: list(map(int,x.split())),l)) for l in L]
S = list(v for s in L[0] for v in s)
S = list(zip(S[0::2],S[1::2])) # list of range (start, length)
2023-12-06 08:57:38 +00:00
low = 99999999999
for s,r in S:
print(f'{s=} {r=}')
for i in range(r):
t = s+i
#print(f'{t=}')
for j,l in en(L[1:]): # for each transformation
ns = None # transformed by a range
#print(f'transf {j}, {l}')
for [dst, src, rg] in l:
#print(f'{src=} {dst=} {rg}')
if src <= t < src+rg:
ns = dst+(t-src)
#print(f'transformed {ns}')
2023-12-06 08:57:38 +00:00
break
if ns:
t = ns
low = min(low, t)
print(low)