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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more