aoc2022/d15/part2c.py

40 lines
868 B
Python
Raw Normal View History

import sys
W = H = 4_000_000
if len(sys.argv)>1: # sample
W = H = 20
# store position that are not reachable, row by row
L = [ [(0,0) for _ in range(32)] for _ in range(H+1) ]
for i,l in enumerate(sys.stdin.read().splitlines()):
(_,_,X,Y,_,_,_,_,A,J) = l.split(" ")
x = int(X[2:-1])
y = int(Y[2:-1])
a = int(A[2:-1])
b = int(J[2:])
d = abs(x-a)+abs(y-b)
for ny in range(y-d, y+d+1):
if ny>=0 and ny<=H:
dy = abs(ny-y)
dx = d-dy
L[ny][i] = (x-dx,x+dx)
#L[ny] = intesec(L[ny], (x-dy,x+dy))
if len(sys.argv)>1: # sample
for l in L:
print(l)
d=0
for (y,I) in enumerate(L):
SI = sorted(I)
maxx = 0
for (a,b) in SI:
if a>maxx+1:
d+=1
print(y, maxx+1, (maxx+1)*4_000_000+y)
maxx = max(maxx,b)
print(d) # should be 1