16 lines
616 B
JavaScript
16 lines
616 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 < 1000; 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 distances = locations.map((a)=>(a.map((b)=>(Math.abs(b))).reduce((b,c)=>(b+c))));
|
|
var maxdist = Math.min.apply(null, distances);
|
|
console.log(maxdist);
|
|
console.log(distances.indexOf(maxdist));
|