Published
Edited
Jun 11, 2022
3 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
jump = (start) =>
d3.randomUniform(
d3.max([start - jumpDist, 0]),
d3.min([start + jumpDist, 1])
)()
Insert cell
jumpDist = 0.2
Insert cell
Insert cell
positionBins = {
// start position, doesn't matter
let position = 0.5;
// add bins for each landing position
const p = [];
for (let i = 0; i < bins; ++i) {
p.push(0);
}
// only start when you press the button
if (start == 0) {
yield [];
return;
}
let showAt = 1;
let showAdder = 1;
// jump a bunch of times
for (let i = 0; i < 10_000_000; ++i) {
position = jump(position);
// add the position after each jump to a bin
p[Math.floor(position * bins)] += 1;
// update the viz after some jumps, in a slick way
if (i > showAt) {
showAdder *= 1.01;
showAt += showAdder;
yield p;
}
}
yield p;
}
Insert cell
bins = 100
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
peakAvg = {
const middleBins = positionBins.slice(bins * jumpDist, 1 - bins * jumpDist);
return d3.mean(middleBins) / d3.sum(positionBins);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
rooms = 1 + 2 + 3 + 4 + 5 + 6 + 7
Insert cell
Insert cell
final_rooms = 1 * 7
Insert cell
answer = final_rooms / rooms
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