>>11759019>You should be able to solve this, right?Yup. I ran a simulation 2 million times, and I got:
gold count: 666038
silver count: 334032
Here is the source code that I used. (Paste it into a html file with script tags around it.)
[code:lit]
const G = 0; // "gold" is encoded as 0
const S = 1; // "silver" is encoded as 1
let box = [ [G,G], [G,S], [S,S] ]; // the contents of the boxes
let count = [0, 0]; // the counts for how many G and S balls were the second ball
for (let i = 0; i < 2_000_000; i++)
{
let x = Math.floor(Math.random() * 3); // random box number (0 to 2)
let y = Math.floor(Math.random() * 2); // random ball number (0 or 1)
//
// box[x] is a random box
// box[x][y] is a random ball from within box[x]
// count[G] is how many gold balls we have counted so far
// count
is how many silver balls we have counted so far
//
if (box[x][y] == G) // if the randomly-selected ball is gold
{
let secondball = box[x][1-y]; // the second ball in the selected box
count[secondball]++; // increment the counter for the second ball
}
}
document.write("gold count: ", count[G], "<br>");
document.write("silver count: ", count, "<br>");
document.write("total: ", count[G] + count);
[/code:lit]