I doubt this is the most performant solution, but it gets the job done for smaller sets of input data.

-- Set up some stufflocalinf=math.abs(1/0)localpoint={__tostring=function(self)returnstring.format("(%03i, %03i)",self[1],self[2])end}-- First of all, read in all the points.-- This is just some boring I/O, and integer parsing.localpoints={}forlineinio.stdin:lines()dolocalpoint=setmetatable({},point)forcoordinateinline:gmatch('%d+')dotable.insert(point,tonumber(coordinate))endtable.insert(points,point)end-- Find smallest axis-aligned rectangle (R) that contains all pointslocalmin_x,max_x,min_y,max_y=inf,0,inf,0for_,pointinipairs(points)dolocalx,y=point[1],point[2]min_x=math.min(x,min_x)min_y=math.min(y,min_y)max_x=math.max(x,max_x)max_y=math.max(y,max_y)end-- Helper function that finds the nearest input point given two coordinates.localfunctionnearest(x,y)localdist,point=inflocalmid=falsefor_,pinipairs(points)dolocald=(math.abs(x-p[1])+math.abs(y-p[2]))ifd==distthenmid=trueelseifd<distthenmid=falsedist=dpoint=pendendreturn(notmid)andpointend-- Mapping points to their respective counts:-- Iterate all points in R, find the nearest input point and add 1 to its count.localcounts={}fory=min_y,max_ydoforx=min_x,max_xdolocalnearest=nearest(x,y)ifnearestthenify==min_yory==max_yorx==max_xorx==min_xthencounts[nearest]=-infelsecounts[nearest]=(counts[nearest]or0)+1endendendend-- Iterate all point-count pairs and remember the highest count; this is our answer.localhighest=0forpoint,countinpairs(counts)doprint(point,count)highest=math.max(count,highest)end-- Output the answer and be happy about it :)print(highest)

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

FULL DISCUSSIONI doubt this is the most performant solution, but it gets the job done for smaller sets of input data.