var input = require("fs").readFileSync("input.txt").toString(); var points = input.split("\n").filter(a=>a).map(a=>(a.split(",").map(b=>(parseInt(b))))); var xmin = points.map(a=>(a[0])).sort((a,b)=>(a-b))[0]; var xmax = points.map(a=>(a[0])).sort((a,b)=>(b-a))[0]; var ymin = points.map(a=>(a[1])).sort((a,b)=>(a-b))[0]; var ymax = points.map(a=>(a[1])).sort((a,b)=>(b-a))[0]; var finitePoints = points.filter(p=>(p[0] != xmin && p[0] != xmax && p[1] != ymin && p[1] != ymax)); var infinitePoints = []; var areas = {}; var man = (xa, ya, xb, yb)=>(Math.abs(xa - xb) + Math.abs(ya - yb)); for(var x = xmin - 200; x <= xmax + 200; x++){ for(var y = ymin - 200; y <= ymax + 200; y++){ var mindist = points.map(p=>(man(p[0], p[1], x, y))).sort((a,b)=>(a-b))[0]; var closest = points.filter(p=>(man(p[0], p[1], x, y) == mindist)); //if(closest.length == 1 && (finitePoints.indexOf(closest[0]) != -1)){ if(closest.length == 1){ if(x == xmin || x == xmax || y == ymin || y == ymax){ if(infinitePoints.indexOf(closest[0]) == -1){ infinitePoints.push(closest[0]); } } if(!areas[closest[0]]){ areas[closest[0]] = 0; } areas[closest[0]]++; } } } for(var point of infinitePoints){ delete areas[point]; } console.log(areas); console.log(infinitePoints); console.log(xmin, xmax, ymin, ymax); console.log(Object.values(areas)); console.log(Math.max.apply(null, Object.values(areas)));