const Moon = require("./Moon"); const { step, parseInput } = require("./common"); const input = parseInput([ "", "", "", "", ]); // const tests = parseInput([ // "", // "", // "", // "", // ]); const tests = parseInput([ "", "", "", "", ]); const moons = input; /** * The amount of steps it takes for a moon to reach its initial state * * Each index in this array corresponds to the index moon in the input. */ const stepsToLoop = [0, 0, 0, 0]; let loopsFound = 0; do { step(moons); if ((loopsFound & 1) == 0) { if (moons[0].hasReachedInitialState()) { loopsFound += 1; } stepsToLoop[0]++; } if ((loopsFound & 2) == 0) { if (moons[1].hasReachedInitialState()) { loopsFound += 2; } stepsToLoop[1]++; } if ((loopsFound & 4) == 0) { if (moons[2].hasReachedInitialState()) { loopsFound += 4; } stepsToLoop[2]++; } if ((loopsFound & 8) == 0) { if (moons[3].hasReachedInitialState()) { loopsFound += 8; } stepsToLoop[3]++; } } while (loopsFound != 15); console.log(stepsToLoop); // console.log(`Steps required to loop: ${steps}`);