Public
Edited
Feb 22, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
mainTableLvl0 = {
const table = [];
for (let i = 2; i < 100; ++i) {
for (let j = i + 1; j < 100; ++j) {
table.push({ i, j, sum: i + j, mul: i * j });
}
}
return table;
}
Insert cell
mainTableLvl0
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
countUniqueSumMul = (table) => {
const mulUnique = {},
sumUnique = {};

table.map((d) => {
if (!mulUnique[d.mul]) mulUnique[d.mul] = 0;
if (!sumUnique[d.sum]) sumUnique[d.sum] = 0;
mulUnique[d.mul] += 1;
sumUnique[d.sum] += 1;
});

return table.map(({ i, j, sum, mul }) => {
const nMul = mulUnique[mul],
nSum = sumUnique[sum];
return { i, j, sum, mul, nSum, nMul };
});
}
Insert cell
Insert cell
mainTableLvl1 = {
return countUniqueSumMul(mainTableLvl0);
}
Insert cell
mainTableLvl1
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
mainTableLvl2 = {
const singleDecomPossible = mainTableLvl1
.filter((e) => e.nMul === 1)
.map(({ mul, sum }) => {
return {
mul,
sum
};
});

const muls = singleDecomPossible.map((d) => d.mul),
sums = singleDecomPossible.map((d) => d.sum);

const avaible = mainTableLvl1.filter(
(d) => !(muls.indexOf(d.mul) > -1 || sums.indexOf(d.sum) > -1)
);

return countUniqueSumMul(avaible);
}
Insert cell
mainTableLvl2
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Plot.plot({
x: { grid: true },
y: { grid: true },
color: { legend: true },
marks: [
Plot.dot(mainTableLvl2, { x: "i", y: "j", stroke: "nSum" }),
Plot.text(mainTableLvl2, {
x: "i",
y: "j",
text: (d) => `${d.i}, ${d.j}, ${d.nSum}`,
fill: "gray",
dy: -8
})
]
})
Insert cell
Insert cell
mainTableLvl3 = {
const mulsUnique = {};
mainTableLvl2.map((d) => {
if (!mulsUnique[d.mul]) mulsUnique[d.mul] = 0;
mulsUnique[d.mul] += 1;
});

const muls = [];
for (const k in mulsUnique) {
if (mulsUnique[k] === 1) muls.push(parseInt(k));
}

const select = mainTableLvl2.filter((d) => muls.indexOf(d.mul) > -1);

return { mulsUnique, muls, select };
}
Insert cell
select3 = countUniqueSumMul(mainTableLvl3.select)
Insert cell
select3
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Plot.plot({
x: { grid: true },
y: { grid: true },
color: { legend: true },
marks: [
Plot.dot(select3, { x: "i", y: "j", stroke: "nSum" }),
Plot.text(select3, {
x: "i",
y: "j",
text: (d) => `${d.i}, ${d.j}, ${d.nSum}`,
fill: "gray",
dy: -8
})
]
})
Insert cell
Insert cell
snipaste_20230221_201141 = FileAttachment("Snipaste_2023-02-21_20-11-41.png").image()
Insert cell
snipaste_20230221_201154 = FileAttachment("Snipaste_2023-02-21_20-11-54.png").image()
Insert cell
snipaste_20230221_201209 = FileAttachment("Snipaste_2023-02-21_20-12-09.png").image()
Insert cell
snipaste_20230221_201219 = FileAttachment("Snipaste_2023-02-21_20-12-19.png").image()
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