fromcollectionsimportdefaultdictfromcollectionsimportCounterfromitertoolsimportproductimportnumpyasnpfromscipy.spatialimportKDTreewithopen("input.txt")asf:coords=[(int(x.split(",")[0]),int(x.split(",")[1]))forxinf]xs,ys=[xforx,yincoords],[yforx,yincoords]# Part 1
t=KDTree(coords)d=defaultdict(int)edge=set()fori,jinproduct(range(max(xs)),range(max(ys))):points,dists=t.query((i,j),k=2,p=1)ifi==0orj==0ori==max(xs)-1orj==max(ys)-1:edge.add(int(dists[0]))ifpoints[0]!=points[1]:d[(i,j)]=dists[0]forp,areainCounter(d.values()).most_common():ifpnotinedge:print(area)break# Part 2
defdist(x,y):returnsum(abs(x-a)+abs(y-b)fora,bincoords)print(sum(1fori,jinproduct(range(max(xs)),range(max(ys)))ifdist(i,j)<10000))

## re: AoC Day 6: Chronal Coordinates VIEW POST

TOP OF THREAD FULL DISCUSSIONPython using a kd-tree.