detectLetters = (grid) => {
function* inner() {
const at = (x, y) => grid[x + y * 40];
for (const letter of d3.range(0, 8)) {
let acc = 0;
for (const y of d3.range(0, 6)) {
for (const x of d3.range(letter * 5, letter * 5 + 4)) {
acc <<= 1;
if (at(x, y) === "#") acc |= 0b1;
}
}
let found = alphabet.find((d) => d[1] === acc);
if (found) {
yield found[0];
} else {
throw new Error(`no match for pattern 0b${acc.toString(2)}`);
}
}
}
return Array.from(inner()).join("");
}