36 lines
11 KiB
JavaScript
36 lines
11 KiB
JavaScript
const input = "[M] [N] [Z] \n[F] [R] [Z] [C] [C] \n[C] [V] [L] [N] [G] [V] \n[W] [L] [T] [H] [V] [F] [H]\n[T] [T] [W] [F] [B] [P] [J] [L]\n[D] [L] [H] [J] [C] [G] [S] [R] [M]\n[L] [B] [C] [P] [S] [D] [M] [Q] [P]\n[B] [N] [J] [S] [Z] [W] [F] [W] [R]\n 1 2 3 4 5 6 7 8 9 \n\nmove 5 from 3 to 6\nmove 2 from 2 to 5\nmove 1 from 9 to 1\nmove 1 from 3 to 1\nmove 5 from 7 to 5\nmove 2 from 9 to 8\nmove 1 from 2 to 8\nmove 1 from 4 to 2\nmove 8 from 1 to 6\nmove 4 from 6 to 9\nmove 1 from 2 to 1\nmove 2 from 4 to 8\nmove 2 from 8 to 4\nmove 3 from 7 to 5\nmove 6 from 5 to 3\nmove 1 from 1 to 8\nmove 1 from 5 to 7\nmove 5 from 6 to 9\nmove 3 from 5 to 8\nmove 2 from 4 to 3\nmove 1 from 7 to 8\nmove 2 from 8 to 6\nmove 2 from 1 to 8\nmove 8 from 3 to 8\nmove 11 from 6 to 3\nmove 1 from 4 to 7\nmove 1 from 3 to 7\nmove 2 from 6 to 1\nmove 7 from 9 to 7\nmove 10 from 3 to 5\nmove 1 from 9 to 3\nmove 2 from 9 to 5\nmove 5 from 5 to 2\nmove 19 from 8 to 6\nmove 1 from 9 to 6\nmove 1 from 3 to 8\nmove 4 from 2 to 6\nmove 1 from 1 to 4\nmove 5 from 8 to 9\nmove 1 from 2 to 1\nmove 6 from 7 to 2\nmove 3 from 5 to 8\nmove 3 from 8 to 1\nmove 2 from 9 to 6\nmove 1 from 7 to 8\nmove 6 from 2 to 7\nmove 1 from 4 to 8\nmove 3 from 8 to 4\nmove 2 from 1 to 5\nmove 7 from 7 to 6\nmove 1 from 7 to 2\nmove 3 from 4 to 6\nmove 2 from 9 to 2\nmove 1 from 1 to 8\nmove 2 from 1 to 3\nmove 1 from 8 to 7\nmove 3 from 2 to 5\nmove 5 from 5 to 8\nmove 4 from 5 to 3\nmove 1 from 7 to 8\nmove 2 from 8 to 1\nmove 1 from 8 to 5\nmove 5 from 3 to 5\nmove 13 from 5 to 1\nmove 1 from 3 to 4\nmove 2 from 8 to 3\nmove 3 from 1 to 4\nmove 1 from 3 to 1\nmove 1 from 8 to 1\nmove 5 from 1 to 9\nmove 1 from 3 to 7\nmove 2 from 9 to 6\nmove 2 from 1 to 7\nmove 3 from 1 to 5\nmove 3 from 1 to 5\nmove 1 from 6 to 1\nmove 4 from 4 to 3\nmove 3 from 9 to 1\nmove 5 from 1 to 7\nmove 7 from 7 to 8\nmove 1 from 3 to 9\nmove 28 from 6 to 8\nmove 5 from 5 to 9\nmove 6 from 6 to 1\nmove 4 from 1 to 8\nmove 5 from 9 to 1\nmove 12 from 8 to 7\nmove 1 from 3 to 8\nmove 6 from 1 to 4\nmove 5 from 4 to 1\nmove 3 from 6 to 4\nmove 2 from 3 to 4\nmove 3 from 1 to 5\nmove 6 from 7 to 1\nmove 2 from 4 to 9\nmove 2 from 5 to 4\nmove 19 from 8 to 1\nmove 4 from 9 to 5\nmove 5 from 4 to 3\nmove 4 from 1 to 4\nmove 5 from 5 to 1\nmove 3 from 8 to 5\nmove 7 from 7 to 3\nmove 14 from 1 to 8\nmove 5 from 4 to 2\nmove 12 from 8 to 7\nmove 1 from 3 to 6\nmove 3 from 5 to 9\nmove 1 from 7 to 8\nmove 8 from 1 to 2\nmove 5 from 1 to 2\nmove 9 from 3 to 4\nmove 8 from 4 to 6\nmove 2 from 1 to 9\nmove 3 from 6 to 1\nmove 5 from 6 to 7\nmove 14 from 7 to 1\nmove 1 from 4 to 7\nmove 6 from 8 to 2\nmove 14 from 1 to 4\nmove 13 from 4 to 9\nmove 2 from 3 to 5\nmove 3 from 1 to 7\nmove 1 from 8 to 4\nmove 1 from 4 to 1\nmove 1 from 1 to 3\nmove 1 from 3 to 4\nmove 1 from 4 to 1\nmove 1 from 6 to 9\nmove 1 from 7 to 6\nmove 1 from 4 to 5\nmove 11 from 9 to 3\nmove 6 from 3 to 8\nmove 5 from 3 to 1\nmove 2 from 8 to 4\nmove 1 from 6 to 2\nmove 7 from 9 to 2\nmove 1 from 7 to 2\nmove 1 from 9 to 8\nmove 2 from 8 to 6\nmove 30 from 2 to 3\nmove 2 from 7 to 2\nmove 2 from 8 to 2\nmove 3 from 8 to 7\nmove 6 from 2 to 5\nmove 1 from 2 to 5\nmove 3 from 1 to 8\nmove 2 from 6 to 7\nmove 1 from 1 to 9\nmove 1 from 9 to 3\nmove 7 from 3 to 1\nmove 6 from 7 to 8\nmove 8 from 3 to 9\nmove 7 from 9 to 1\nmove 1 from 5 to 8\nmove 7 from 5 to 9\nmove 2 from 4 to 2\nmove 11 from 3 to 6\nmove 2 from 2 to 7\nmove 11 from 1 to 8\nmove 2 from 5 to 4\nmove 11 from 6 to 4\nmove 12 from 4 to 9\nmove 4 from 1 to 5\nmove 3 from 7 to 9\nmove 12 from 8 to 4\nmove 1 from 1 to 7\nmove 6 from 8 to 3\nmove 2 from 3 to 5\nmove 3 from 8 to 4\nmove 3 from 3 to 7\nmove 9 from 9 to 7\nmove 5 from 3 to 9\nmove 1 from 3 to 2\nmove 13 from 7 to 5\nmove 1 from 2 to 6\nmove 1 from 6 to 1\nmove 1 from 1 to 6\nmove 16 from 4 to 5\nmove 1 from 5 to 6\nmove 16 from 5 to 4\nmove 13 from 4 to 5\nmove 3 from 4 to 2\nmove 1 from 6 to 7\nmove 3 from 2 to 1\nmove 8 from 5 to 2\nmove 3 from 1 to 4\nmove 1 from 7 to 9\nmove 14 from 5 to 1\nmove 10 from 1 to 5\nmove 1 from 2 to 8\nmove 19 from 9 to 1\nmove 1 from 9 to 1\nmove 6 from 2 to 7\nmove 4 from 1 to 7\nmove 1 from 8 to 6\nmove 16 from 5 to 3\nmove 1 from 5 to 4\nmove 2 from 5 to 2\nmove 1 from 5 to 6\nmove 1 from 6 to 5\nmove 1 from 2 to 4\nmove 7 from 7 to 2\nmove 4 from 4 to 7\nmove 2 from 6 to 2\nmove 8 from 2 to 9\nmove 4 from 9 to 2\nmove 16 from 3 to 7\nmove 4 from 9 to 7\nmove 14 from 1 to 3\nmove 26 from 7 to 8\nmove 1 from 5 to 4\nmove 20 from 8 to 4\nmove 5 from 1 to 8\nmove 2 from 4 to 6\nmove 4 from 3 to 2\nmove 1 from 6 to 5\nmove 8 from 2 to 4\nmove 1 from 6 to 5\nmove 1 from 7 to 8\nmove 8 from 3 to 1\nmove 6 from 1 to 9\nmove 1 from 3 to 6\nmove 14 from 4 to 1\nmove 1 from 3 to 8\nmove 2 from 2 to 1\nmove 1 from 6 to 8\nmove 1 from 2 to 8\nmove 5 from 8 to 1\nmove 2 from 1 to 6\nmove 2 from 5 to 9\nmove 1 from 6 to 3\nmove 1 from 6 to 1\nmove 5 from 9 to 2\nmove 5 from 4 to 1\nmove 5 from 4 to 2\nmove 16 from 1 to 8\nmove 9 from 1 to 4\nmove 24 from 8 to 6\nmove 1 from 8 to 7\nmove 7 from 6 to 5\nmove 1 from 3 to 4\nmove 3 from 1 to 8\nmove 3 from 5 to 8\nmove 10 from 4 to 8\nmove 3 from 4 to 6\nmove 1 from 7 to 4\nmove 20 from 6 to 7\nmove 1 from 4 to 9\nmove 1 from 4 to 9\nmove 7 from 2 to 3\nmove 13 from 8 to 9\nmove 4 from 5 to 9\nmove 4 from 8 to 5\nmove 18 from 9 to 2\nmove 14 from 7 to 5\nmove 6 from 3 to 8\nmove 1 from 3 to 2\nmove 1 from 8 to 6\nmove 4 from 8 to 2\nmove 1 from 2 to 3\nmove 17 from 5 to 3\nmove 18 from 3 to 5\nmove 6 from 7 to 2\nmove 3 from 9 to 7\nmove 1 from 8 to 6\nmove 5 from 2 to 5\nmove 26 from 2 to 7\nmove 1 from 6 to 9\nmove 29 from 7 to 9\nmove 15 from 5 to 2\nmove 1 from 6 to 7\nmove 8 from 9 to 2\nmove 14 from 2 to 6\nmove 16 from 9 to 1\nmove 6 from 9 to 1\nmove 1 from 7 to 1\nmove 3 from 2 to 1\nmove 5 from 2 to 6\nmove 15 from 1 to 4\nmove 1 from 2 to 8\nmove 1 from 9 to 7\nmove 1 from 8 to 6\nmove 19 from 6 to 7\nmove 10 from 1 to 8\nmove 4 from 8 to 3\nmove 1 from 7 to 5\nmove 3 from 5 to 3\nmove 13 from 7 to 6\nmove 2 from 8 to 9\nmove 7 from 3 to 6\nmove 5 from 5 to 3\nmove 1 from 1 to 6\nmove 2 from 5 to 1\nmove 4 from 4 to 8\nmove 7 from 8 to 7\nmove 8 from 7 to 3\nmove 1 from 8 to 4\nmove 2 from 9 to 2\nmove 8 from 6 to 5\nmove 1 from 4 to 5\nmove 4 from 5 to 4\nmove 2 from 2 to 8\nmove 9 from 4 to 5\nmove 2 from 1 to 9\nmove 2 from 8 to 9\nmove 14 from 6 to 4\nmove 5 from 3 to 4\nmove 3 from 9 to 7\nmove 3 from 5 to 3\nmove 2 from 4 to 8\nmove 2 from 4 to 7\nmove 2 from 8 to 9\nmove 4 from 5 to 8\nmove 16 from 4 to 6\nmove 1 from 9 to 6\nmove 3 from 7 to 5\nmove 7 from 7 to 5\nmove 10 from 5 to 1\nmove 6 from 3 to 8\nmove 2 from 9 to 3\nmove 3 from 6 to 9\nmove 3 from 3 to 6\nmove 2 from 1 to 7\nmove 13 from 6 to 2\nmove 2 from 4 to 5\nmove 2 from 7 to 6\nmove 2 from 6 to 7\nmove 2 from 4 to 1\nmove 3 from 9 to 5\nmove 1 from 1 to 4\nmove 3 from 2 to 5\nmove 2 from 4 to 1\nmove 2 from 3 to 2\nmove 5 from 8 to 5\nmove 1 from 7 to 2\nmove 1 from 7 to 1\nmove 1 from 3 to 5\nmove 1 from 8 to 7\nmove 1 from 6 to 7\nmove 1 from 3 to 5\nmove 12 from 5 to 6\nmove 6 from 6 to 2\nmove 1 from 7 to 4\nmove 1 from 5 to 7\nmove 2 from 8 to 9\nmove 1 from 9 to 6\nmove 1 from 8 to 9\nmove 5 from 6 to 9\nmove 1 from 8 to 1\nmove 14 from 2 to 4\nmove 1 from 7 to 1\nmove 1 from 7 to 2\nmove 3 from 2 to 3\nmove 2 from 3 to 4\nmove 1 from 2 to 4\nmove 4 from 6 to 2\nmove 8 from 5 to 8\nmove 15 from 4 to 8\nmove 3 from 4 to 8\nmove 7 from 8 to 4\nmove 6 from 1 to 3\nmove 1 from 6 to 1\nmove 5 from 4 to 8\nmove 7 from 9 to 1\nmove 1 from 5 to 6\nmove 4 from 2 to 6\nmove 10 from 1 to 8\nmove 29 from 8 to 3\nmove 1 from 4 to 5\nmove 1 from 4 to 6\nmove 6 from 1 to 4\nmove 1 from 5 to 8\nmove 3 from 4 to 2\nmove 27 from 3 to 7\nmove 18 from 7 to 9\nmove 5 from 6 to 3\nmove 7 from 7 to 4\nmove 1 from 7 to 8\nmove 9 from 3 to 5\nmove 5 from 3 to 6\nmove 3 from 4 to 2\nmove 1 from 7 to 2\nmove 2 from 8 to 4\nmove 2 from 8 to 6\nmove 2 from 8 to 6\nmove 8 from 2 to 1\nmove 7 from 5 to 4\nmove 1 from 8 to 9\nmove 4 from 1 to 5\nmove 1 from 2 to 9\nmove 8 from 6 to 3\nmove 3 from 1 to 8\nmove 1 from 1 to 7\nmove 8 from 3 to 6\nmove 2 from 8 to 3\nmove 1 from 3 to 6\nmove 4 from 6 to 7\nmove 16 from 4 to 2\nmove 1 from 3 to 5\nmove 2 from 6 to 4\nmove 1 from 2 to 3\nmove 2 from 7 to 3\nmove 2 from 7 to 8\nmove 3 from 6 to 7\nmove 4 from 5 to 2\nmove 2 from 4 to 2\nmove 4 from 9 to 8\nmove 3 from 5 to 1\nmove 3 from 1 to 6\nmove 6 from 9 to 1\nmove 4 from 7 to 9\nmove 8 from 9 to 5\nmove 4 from 5 to 2\nmove 7 from 8 to 6\nmove 11 from 6 to 8\nmove 4 from 1 to 2\nmove 3 from 8 to 9\nmove 5 from 8 to 7\nmove 2 from 1 to 6\nmove 4 from 5 to 6\nmove 2 from 7 to 9\nmove 2 from 7 to 3\nmove 5 from 6 to 2\nmove 4 from 3 to 1\nmove 1 from 7 to 2\nmove 1 from 3 to 2\nmove 2 from 6 to 7\nmove 1 from 1 to 6\nmove 6 from 9 to 6\nmove 1 from 7 to 6\nmove 1 from 7 to 6\nmove 2 from 1 to 7\nmove 2 from 8 to 6\nmove 4 from 9 to 2\nmove 17 from 2 to 6\nmove 1 from 9 to 4\nmove 1 from 1 to 3\nmove 1 from 4 to 1\nmove 20 from 2 to 8\nmove 2 from 7 to 6\nmove 2 from 2 to 5\nmove 1 from 3 to 1\nmove 1 from 2 to 5\nmove 6 from 8 to 6\nmove 2 from 5 to 6\nmove 3 from 6 to 4\nmove 1 from 1 to 4\nmove 15 from 8 to 2\nmove 11 from 2 to 9\nmove 1 from 1 to 3\nmove 10 from 9 to 4\nmove 1 from 9 to 8\nmove 12 from 6 to 3\nmove 1 from 8 to 7\nmove 1 from 5 to 4\nmove 8 from 4 to 7\nmove 5 from 3 to 4\nmove 7 from 6 to 4\nmove 3 from 3 to 6\nmove 3 from 3 to 2\nmove 1 from 3 to 6\nmove 17 from 4 to 3\nmove 1 from 3 to 4\nmove 2 from 4 to 9\nmove 14 from 3 to 6\nmove 2 from 2 to 7\nmove 1 from 4 to 9\nmove 8 from 7 to 6\nmove 1 from 3 to 4\nmove 9 from 6 to 2\nmove 1 from 4 to 2\nmove 26 from 6 to 2\nmove 27 from 2 to 6\nmove 10 from 2 to 4\nmove 1 from 7 to 6\nmove 28 from 6 to 2\nmove 21 from 2 to 4\nmove 2 from 6 to 7\nmove 3 from 2 to 1\nmove 5 from 6 to 5\nmove 3 from 5 to 2\nmove 1 from 7 to 4\nmove 11 from 2 to 4\nmove 21 from 4 to 9\nmove 1 from 5 to 8\nmove 1 from 8 to 6\nmove 18 from 9 to 7\nmove 1 from 5 to 7\nmove 3 from 9 to 8\nmove 1 from 6 to 7\nmove 1 from 3 to 5\nmove 1 from 8 to 3\nmove 22 from 7 to 5\nmove 13 from 5 to 1\nmove 16 from 4 to 5\nmove 3 from 1 to 4\nmove 2 from 3 to 9\nmove 3 from 9 to 7\nmove 6 from 4 to 6\nmove 1 from 4 to 2\nmove 2 from 7 to 3".split("\n");
|
|
|
|
console.log("Input: ", input);
|
|
const startStackRows = input.slice(0,8);
|
|
const stacks = [[], [], [], [], [], [], [], [], []]
|
|
startStackRows.forEach(row => {
|
|
for(let i = 0; i < 9; ++i) {
|
|
const letter = row[1 + i*4];
|
|
if(letter !== " "){
|
|
stacks[i].unshift(letter);
|
|
}
|
|
}
|
|
});
|
|
|
|
console.log("Stacks: ", stacks);
|
|
|
|
const moveCrate = (a, b) => {
|
|
stacks[b - 1].push(stacks[a-1].pop());
|
|
|
|
};
|
|
|
|
const moveXCrates = (n, a, b) => {
|
|
for(let i = 0; i < n; ++i) {
|
|
moveCrate(a, b);
|
|
}
|
|
}
|
|
|
|
const steps = input.slice(10).map(x => {
|
|
const a = x.split(" ");
|
|
return [a[1], a[3], a[5]];
|
|
});
|
|
|
|
console.log("steps: ", steps);
|
|
|
|
steps.forEach(([n, a, b]) => moveXCrates(n, a, b));
|
|
console.log("stacks: ", stacks);
|