// it used to be even more complicated, but even i couldn't handle 300 lines of pure spaghetti
const needs_more_closure = (() => {
class linkedCell {
value: number;
north: linkedCell;
east: linkedCell;
south: linkedCell;
west: linkedCell;
};
let border = new linkedCell;
border.value = 1;
let x: number, y: number, arr: linkedCell[][] = [], passarr: linkedCell[] = [];
const marks: [
(px: number) => ((py: number) => void),
(cell: number) => number,
(e: number[]) => number,
(e: number[]) => number[][]
] = [
(px: number) => ((py: number) => { x = px; y = py }),
(cell: number) => {
let me = new linkedCell;
me.value = cell;
me.north = border;
me.east = border;
me.south = border;
me.west = border;
if (passarr.length > 0) {
let prev = passarr[passarr.length - 1];
prev.east = me;
me.west = prev;
}
passarr.push(me);
return 0;
},
(e: number[]) => {
passarr.map((a, b) => {
if (arr.length > 0) {
let c = arr[arr.length - 1][b];
a.north = c;
c.south = a;
}
});
arr.push([...passarr]);
passarr = [];
return 0;
},
(e: number[]) => {
let d: number;
arr[x][y].value = 2;
do {
d = 0
for (let n of arr) {
for (let m of n) {
if (m.value == 0) {
if (m.north.value == 2 || m.east.value == 2 || m.south.value == 2 || m.west.value == 2) {
m.value = 2;
d = 1;
}
}
}
}
} while (d)
return arr.map(n => n.map(m => [0, 1, 1][m.value]));
}
]
return marks;
})()
function entry(grid: boolean[][], x: number, y: number): boolean[][] {
needs_more_closure[0](x)(y);
return needs_more_closure[3]
(grid.map(
a => needs_more_closure[2]
(a.map(
b => needs_more_closure[1](Number(b))
))
))
.map(a => a.map(b => Boolean(b)));
}
single comment. simplistic and inefficient spaghetti. Kestrel probably
post a comment