Published
Edited
Mar 15, 2022
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof play = html`<form>${Object.assign(html`<button type=button>Play`, {onclick: event => event.currentTarget.dispatchEvent(new CustomEvent("input", {bubbles: true}))})}`

Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function playGame(totalFunds, p, totalBets, bet=1, funds=[]) {
const flip = flipCoin();
if (bet <= totalBets) {
if (flip) {
const newFunds = totalFunds + (totalFunds*p);
return playGame(
newFunds,
p,
totalBets,
bet + 1,
R.append({bet, funds: newFunds}, funds),
);
}
const newFunds = totalFunds - (totalFunds*p);
return playGame(
newFunds,
p,
totalBets,
bet + 1,
R.append({bet, funds: newFunds}, funds),
);
}
return funds;
}
Insert cell
function simulate(numOfSim, sim=0, endingFunds=[]) {
if (sim < numOfSim) {
return simulate(
numOfSim,
sim + 1,
R.append(R.map(R.assoc('sim', sim), playGame(startingBankroll2, p, numBets)), endingFunds)
);
}
return endingFunds;
}
Insert cell
vegalite = require("vega-embed@3")
Insert cell
import { number, radio } from "@jashkenas/inputs"
Insert cell
import {R} from "@itacirgabral/ramda"
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
mutable bankroll = 25
Insert cell
mutable winner = null
Insert cell
mutable winnerInitialized = false
Insert cell
mutable winResult = 0
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
mutable currentRound = 1;
Insert cell
mutable clicked = false;
Insert cell
mutable resetClicked = false;
Insert cell
mutable d = []
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