Published
Edited
Jan 19, 2021
Insert cell
Insert cell
Insert cell
Insert cell
result1 = {
const patterns = d3.range(1, 10).map(e => String(e).repeat(6));
const k = 5n;
const result = [];
const t0 = new Date();
for (let k = 2n; k < 10; k++) {
result.push(patterns.map(p => ({ ...{ pattern: p }, ...search(k, p) })));
const dt = new Date() - t0;
yield md`done k=2..${k} in ${dt} ms`;
}
const final = result.flat();
yield final;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
searchRndPattern = (k, patternLength) => {
const pLength = 5;
const randomDigit = () => Math.floor(Math.random() * 10);
const pattern = d3
.range(patternLength)
.map(_ => String(randomDigit()))
.join('');

return search(k, pattern);
}
Insert cell
Insert cell
Insert cell
{
newRndRun;
const k = 5n;
const trials = 20;

const patternLength = 6;
const stats = { success: 0, fails: 0 };
for (let i = 0; i < trials; i++) {
const res = searchRndPattern(k, patternLength);
if (res) {
stats.success += 1;
} else {
stats.fails += 1;
}

yield stats;
}
}
Insert cell
Insert cell
{
// const pattern = '12345678'; // about 20s
const pattern = '345678'; // instant
const k = 5n;
const nbSol = 1;
const maxExp = 20000n;
const t0 = new Date();
const result = search(k, pattern, nbSol, maxExp);
const t1 = new Date();
return { ...result, ...{ dt: t1 - t0 } };
}
Insert cell
Insert cell
Insert cell
Insert cell
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