function processBrightness(instrs) {
const grid = AOC.gInit(1000, 1000, 0);
const regex = /(toggle|turn on|turn off) (\d+),(\d+) through (\d+),(\d+)/;
for (const instr of instrs) {
const match = instr.match(regex);
const [action, c0, r0, c1, r1] = [match[1], ...match.slice(2).map(Number)];
for (let r = r0; r <= r1; r++) {
for (let c = c0; c <= c1; c++) {
grid[r][c] =
action === "turn on"
? grid[r][c] + 1
: action === "turn off"
? Math.max(0, grid[r][c] - 1)
: grid[r][c] + 2;
}
}
}
return AOC.sum(grid.flat());
}