Public
Edited
Feb 10, 2024
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Mat = Data.split("\n").slice(1, -1);
Insert cell
char = { return ([i, j]) => Mat[i][j]; }
Insert cell
isWall = { return (p) => char(p) == "#"; }
Insert cell
isOrigin = { return (p) => char(p) == "@"; }
Insert cell
isDestination = { return (p) => char(p) == "&"; }
Insert cell
locateObjects = {
return (match) => {
let m = Mat.length;
let n = Mat[0].length;
let objects = {};
for (let i = 0; i < m; i++) {
for (let j = 0; j < n; j++) {
const p = [i, j];
const c = char(p);
if (match(p)) {
objects[c] = p;
}
}
}

return objects;
}
}
Insert cell
Insert cell
Objects = locateObjects(p => isOrigin(p) || isDestination(p))
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more