function parseStack(input) {
const stacks = [];
const moves = [];
const [part1, part2] = input.split("\n\n");
for (const line of part1.split("\n").slice(0, -1)) {
for (let i = 1, n = line.length, j = 1; i < n; i += 4, ++j) {
switch (line[i]) {
case " ": continue;
default:
(stacks[j] ??= []).push(line[i]);
break;
}
}
}
for (const line of part2.trim().split("\n")) {
const {groups: {n, src, dst}} = /^move (?<n>\d+) from (?<src>\d+) to (?<dst>\d+)$/.exec(line);
moves.push({n, src, dst});
}
return {stacks, moves};
}