parsed = (s) => {
const [seeds, ...rest] = s;
const identity = { apply: (x) => x };
const maps = rest.map((lines) => {
const [name, ...ranges] = lines.split("\n");
const fns = ranges.map((r) => {
const [d, s, n] = r.split(" ").map(Number);
return { applies: (x) => s <= x && x < s + n, apply: (x) => d + x - s };
});
return (x) => (fns.find((fn) => fn.applies(x)) ?? identity).apply(x);
});
return { seeds: seeds.split(" ").slice(1).map(Number), maps };
}