This commit is contained in:
2022-12-05 21:05:25 +00:00
parent f214ed1fe3
commit e43eea0f6e
3 changed files with 15 additions and 20 deletions

View File

@@ -20,6 +20,8 @@ for (let idx = stack.length - 2; idx >= 0; idx--) {
}
}
let stackInputPart2: any[] = JSON.parse(JSON.stringify(stackInput));
for (let idx = 0; idx < rules.length; idx++) {
const [move, from, to] = rules[idx].split(' ').filter(el => !isNaN(Number(el))).map(Number);
for (let num = 0; num < move; num++) stackInput[to - 1].push(stackInput[from - 1].pop());
@@ -29,4 +31,16 @@ const part1 = stackInput.map(buck => buck[buck.length - 1]).join("");
console.log("Part1:", part1);
elapsed = process.hrtime.bigint() - start;
elapsed = process.hrtime.bigint() - start;
for (let idx = 0; idx < rules.length; idx++) {
const [move, from, to] = rules[idx].split(' ').filter(el => !isNaN(Number(el))).map(Number);
let cratemover9001: any[] = [];
for (let num = 0; num < move; num++) cratemover9001.push(stackInputPart2[from - 1].pop());
stackInputPart2[to - 1] = stackInputPart2[to - 1].concat(cratemover9001.reverse());
}
const part2 = stackInputPart2.map(buck => buck[buck.length - 1]).join("");
console.log("Part2:", part2);