function directView(pos0, grid) {
const [nRows, nCols] = [grid.length, grid[0].length];
const removeBlocked = (sortedLocations, visible) => {
if (sortedLocations.length === 0) {
return visible;
}
const pos = sortedLocations.shift();
const invisible = blocked(nRows, nCols, pos0, pos);
return removeBlocked(
sortedLocations.filter((p) => !invisible.includes(p)),
[pos, ...visible]
);
};
return removeBlocked(otherAsteroids(pos0, grid), []).reduce((g, pos) => {
const [r, c] = decode(pos);
g[r][c] = "#";
return g;
}, AOC.gInit(nRows, nCols, "."));
}