|
@@ -53,3 +53,22 @@ function calculateGravity(moonA, moonB) {
|
|
moonB.z > moonA.z ? 1 : (moonB.z < moonA.z ? -1 : 0),
|
|
moonB.z > moonA.z ? 1 : (moonB.z < moonA.z ? -1 : 0),
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @param {string[]} inputs The day's input
|
|
|
|
+ * @returns {Vector3[]} An array of Vector3's representing the positions of moons
|
|
|
|
+ */
|
|
|
|
+function parseInput(inputs) {
|
|
|
|
+ const moons = [];
|
|
|
|
+ const parseRegex = new RegExp(/x=(-?\d+), y=(-?\d+), z=(-?\d+)/);
|
|
|
|
+
|
|
|
|
+ for (const position of inputs) {
|
|
|
|
+ // eslint-disable-next-line no-shadow-restricted-names
|
|
|
|
+ const [undefined, x, y, z] = position.match(parseRegex);
|
|
|
|
+ moons.push(new Vector3(parseInt(x, 10), parseInt(y, 10), parseInt(z, 10)));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return moons;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+console.log(util.inspect(parseInput(input)));
|