function parse(input) {
const line = (txt, n) => txt.split("\n")[n];
const parseTest = (op, arg) => {
if (arg === "old") {
return (wl) => wl * wl;
}
if (op === "*") {
return (wl) => wl * Number(arg);
}
return (wl) => wl + Number(arg);
};
const parseMonkey = (txt) => ({
items: JSON.parse("[" + line(txt, 1).slice(18) + "]"),
operation: parseTest(line(txt, 2)[23], line(txt, 2).slice(25)),
divisor: Number(line(txt, 3).slice(21)),
tMonkey: Number(line(txt, 4).slice(29)),
fMonkey: Number(line(txt, 5).slice(30)),
inspected: 0
});
return input.split("\n\n").map(parseMonkey);
}