Public
Edited
Apr 21
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
md`A pool of size 8 has an average duration of ${d3.mean(
poolSamples.filter((d) => d.size === 8).map((d) => d.duration)
)}, a median of ${d3.median(
poolSamples.filter((d) => d.size === 8).map((d) => d.duration)
)}`
Insert cell
poolSamples = poolDurations.map((sample) => ({
size: sample[0].length,
duration: sample.length
}))
Insert cell
samplesRollup = d3
.flatRollup(
poolSamples,
(d) => d.length,
(d) => d.size,
(d) => d.duration
)
.map(([size, duration, occurrences]) => ({
size,
duration,
occurrences
}))
Insert cell
poolDurations = [runSamples(4, sampleSize), runSamples(6, sampleSize), runSamples(8, sampleSize)].flat()
Insert cell
runSamples = (size, trials) => Array(trials).fill(0).map(() => runPool(size))
Insert cell
runPool = (size) => {
let pool = startPool(size);
while (!isDepleted(pool)) {
pool = trigger(pool)
}
return pool;
}
Insert cell
isDepleted = (pool) => pool[pool.length - 1].every((x) => x < 4)
Insert cell
trigger = pool =>
{
const size = pool[pool.length - 1].filter(x => x > 3).length
return pool.concat([rollSet(size)])
}

Insert cell
startPool = (size) => [rollSet(size)]
Insert cell
rollSet = (size) =>
Array(size)
.fill(0)
.map(() => Math.floor(Math.random() * 6 + 1))
Insert cell
colorScheme = "Category10"
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