adventofcode-2017/day20/part2.js
2017-12-25 23:22:40 +00:00

15 lines
599 B
JavaScript

var input = require("fs").readFileSync("input.txt").toString();
var inputjson = "[{" + input.replace(/([a-z])=</g, "\"$1\": [").replace(/>/g, "]").replace(/\n/g, "},\n{").slice(0,-3) + "]";
var objects = JSON.parse(inputjson);
for(var i = 0; i < 10000; i++){
objects = objects.map(o=>{
o.v = o.v.map((v,x)=>(v + o.a[x]));
o.p = o.p.map((p,x)=>(p + o.v[x]));
return o;
});
var locations = objects.map(o=>(o.p));
var locationsStr = locations.map((a)=>(a.join(",")));
objects = objects.filter((a)=>(locationsStr.filter((b)=>(b==a.p.join(","))).length == 1));
console.log(objects.length);
}