23 lines
636 B
JavaScript
23 lines
636 B
JavaScript
|
var input = require("fs").readFileSync("input_2.txt").toString().replace(/\r/g, "");
|
||
|
var cogs = input.split("\n").filter((a)=>(a)).map((line)=>{
|
||
|
var lineParts = line.match(/Disc #([1-9]+) has ([1-9]+) positions; at time=0, it is at position ([0-9]+)./);
|
||
|
return {
|
||
|
number: parseInt(lineParts[1]),
|
||
|
positions: parseInt(lineParts[2]),
|
||
|
startPos: parseInt(lineParts[3]),
|
||
|
};
|
||
|
}).sort((a, b)=>(a.number - b.number));
|
||
|
|
||
|
var t = -1;
|
||
|
var solved = false;
|
||
|
while(!solved){
|
||
|
solved = true;
|
||
|
t++;
|
||
|
for(var cog of cogs){
|
||
|
if(((cog.number + cog.startPos + t) % cog.positions) != 0){
|
||
|
solved = false;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
console.log(t);
|