2022-12-05 16:16:31 +00:00
|
|
|
import * as R from "remeda";
|
2022-12-07 23:42:05 +00:00
|
|
|
|
|
|
|
import { parseLines, spy } from "./part1.js";
|
|
|
|
|
|
|
|
function moveStacks([stacks, commands]) {
|
|
|
|
for (let [move, from, to] of commands) {
|
|
|
|
console.log({ move, from, to });
|
|
|
|
|
|
|
|
stacks[to - 1].push(
|
|
|
|
...stacks[from - 1].splice(stacks[from - 1].length - move)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return stacks;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default R.createPipe(
|
|
|
|
(text) => text.split("\n\n"),
|
|
|
|
parseLines,
|
|
|
|
moveStacks,
|
|
|
|
spy,
|
|
|
|
R.map((x) => x.pop()),
|
|
|
|
(x) => x.join("")
|
|
|
|
);
|