Public
Edited
Mar 26, 2024
Insert cell
Insert cell
{
const roll = () => {
return Math.random();
};
let leaderboard = {
aliceWins: 0,
bobWins: 0,
};

while (leaderboard.aliceWins + leaderboard.bobWins < 100){

let scoreboard = {
alicePoints: 0,
bobPoints: 0,
alice5bob3: false
};
let mark = roll();

while (scoreboard.alicePoints < 6 && scoreboard.bobPoints < 6) {
let ball = roll();

if (ball < mark) {
scoreboard.alicePoints = scoreboard.alicePoints + 1;
} else if (ball > mark) {
scoreboard.bobPoints = scoreboard.bobPoints + 1;
}
if (scoreboard.alicePoints === 5 && scoreboard.bobPoints === 3) {
scoreboard.alice5bob3 = true;
}
}
if (scoreboard.alice5bob3 === true) {
if (scoreboard.alicePoints === 6) {
leaderboard.aliceWins = leaderboard.aliceWins + 1;
} else {
leaderboard.bobWins = leaderboard.bobWins + 1;}
}
}
let aliceOdds = leaderboard.aliceWins/leaderboard.bobWins;
return `Alice has odds of winning of ${aliceOdds} :1`;
}
Insert cell
Insert cell
{
const roll = () => {
return Math.random();
};
let leaderboard = {
aliceWins: 0,
bobWins: 0,
};

for (let i = 0 ; i < 10000 ; i = i + 1){
let scoreboard = {
alicePoints: 0,
bobPoints: 0,
alice5bob3: false
};
let mark = roll();

while (scoreboard.alicePoints < 6 && scoreboard.bobPoints < 6) {
let ball = roll();

if (ball < mark) {
scoreboard.alicePoints = scoreboard.alicePoints + 1;
} else if (ball > mark) {
scoreboard.bobPoints = scoreboard.bobPoints + 1;
}
if (scoreboard.alicePoints === 5 && scoreboard.bobPoints === 3) {
scoreboard.alice5bob3 = true;
}
}
if (scoreboard.alice5bob3 === true) {
if (scoreboard.alicePoints === 6) {
leaderboard.aliceWins = leaderboard.aliceWins + 1;
} else {
leaderboard.bobWins = leaderboard.bobWins + 1;}
}
}
let aliceOdds = leaderboard.aliceWins/leaderboard.bobWins
return `Alice has odds of winning of ${aliceOdds} :1`
}
Insert cell
{
let result = [];

for (let i=0 ; i < 10 ; i = i +1) {
result.push (i);
}
return result;
}
Insert cell
{
let seqs = ["ATGCGATCGAT", "ATTCGCTACG", "ATGGGCATACGAC"];
let hasStart = [];

for (let i = 0; i < seqs.length; i = i + 1) {
if (seqs[i].startsWith("ATG")) {
hasStart.push(seqs[i]);
}
}
return hasStart;
}
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