Published
Edited
Apr 6, 2019
3 stars
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, wagerAmount, totalBets, bet=1, funds=[]) {

const rollResultSuccess = flipUnfairCoin();
if (bet <= totalBets) {
if (rollResultSuccess) {
const newFunds = totalFunds + wagerAmount;
return playGame(
newFunds,
wagerAmount,
totalBets,
bet + 1,
R.append({bet, funds: newFunds}, funds),
);
}
const newFunds = totalFunds - wagerAmount;
return playGame(
newFunds,
wagerAmount,
totalBets,
bet + 1,
R.append({bet, funds: newFunds}, funds),
);
}
return funds;
}
Insert cell
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(initialFunds, wagerAmount, totalPlays)), endingFunds)
);
}
return endingFunds;
}
Insert cell
Insert cell
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