aoc2022/d15/part1.py

53 lines
894 B
Python

import sys
from collections import defaultdict
BX = 1765036
BY = 2000000
def mtn(P,Q):
(x,y) = P
(u,v) = Q
return abs(u-x)+abs(v-y)
S = set()
B = set()
P = dict()
Q = defaultdict(list)
for l in 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:])
S.add((x,y))
B.add((a,b))
P[(x,y)] = (a,b)
Q[(a,b)].append((x,y))
if len(S) < 20:
BX = 2
BY = 10
Xs = set()
for s in S:
(x,y) = s
sB = P[s] # nearest bc
dB = mtn(s,sB) # max range before first bc
dy = abs(y-BY) # to reach THE bc
r = dB - dy
if len(S) < 20:
print(s, sB, (BX,BY), dB, dy, r)
if r > 0:
for d in range(-r,r+1):
nx = x+d
if abs(nx-BX)>=0:
Xs.add(nx)
print(len(Xs)-1)
if len(S) < 20:
print(Xs)