31 lines
703 B
JavaScript
31 lines
703 B
JavaScript
var input = require("fs").readFileSync("input.txt").toString().split("\n").filter(a=>a);
|
|
var sqs = input.map((a)=>(a.match(/#\d+ @ (\d+),(\d+): (\d+)x(\d+)/)).map(a=>(parseInt(a))).filter(a=>(a>=0)));
|
|
|
|
function overlapa(a, b){
|
|
xa1 = a[0]
|
|
xa2 = a[0] + a[2] - 1;
|
|
xb1 = b[0];
|
|
xb2 = b[0] + b[2] - 1;
|
|
|
|
ya1 = a[1]
|
|
ya2 = a[1] + a[3] - 1;
|
|
yb1 = b[1];
|
|
yb2 = b[1] + b[3] - 1;
|
|
|
|
return (
|
|
(((xa1 >= xb1) && (xa1 <= xb2)) || ((xa2 >= xb1) && (xa2 <= xb2)))
|
|
&&
|
|
(((ya1 >= yb1) && (ya1 <= yb2)) || ((ya2 >= yb1) && (ya2 <= yb2)))
|
|
)
|
|
}
|
|
|
|
function overlap(a,b){
|
|
return overlapa(a,b) || overlapa(b,a);
|
|
}
|
|
|
|
for(var i in sqs){
|
|
if(sqs.filter(sq=>(overlap(sq, sqs[i]))).length == 1){
|
|
console.log(i + 1);
|
|
}
|
|
}
|