findSmudge = ({ cols, rows }) => {
const currentScore = test(cols) ?? 10000 * test(rows);
const C = d3.group(
cols.map((c, i) => ({ c, i })),
({ c }) => c
);
const R = d3.group(
rows.map((c, i) => ({ c, i })),
({ c }) => c
);
for (let x = 0; x < cols.length; ++x) {
for (let y = 0; y < rows.length; ++y) {
cols[x] ^= 1 << y;
rows[y] ^= 1 << x;
let score;
if (C.has(cols[x])) score = test(cols, currentScore);
if (!score && R.has(rows[y]))
score = 100 * test(rows, currentScore / 10000);
cols[x] ^= 1 << y;
rows[y] ^= 1 << x;
if (score) return { x, y, score };
}
}
}