function part2(input) {
const [p1, p2] = wires(input).map(path);
const crossings = intersectingWires([p1, p2]);
const distances = (p) =>
p
.filter(([x, y, d]) => crossings.has(toStr([x, y])))
.sort((a, b) => manhattan(a) - manhattan(b))
.map(([x, y, d]) => d);
return Math.min(
...AOC.zipWith((a, b) => a + b, distances(p1), distances(p2))
);
}