site banner

Friday Fun Thread for September 6, 2024

Be advised: this thread is not for serious in-depth discussion of weighty topics (we have a link for that), this thread is not for anything Culture War related. This thread is for Fun. You got jokes? Share 'em. You got silly questions? Ask 'em.

2
Jump in the discussion.

No email address required.

So, if you treat the coins as not being fungible, this makes sense. But they are fungible? So why wouldn't it be 50%? The question isn't about pulling a specific gold coin, but any gold coin. Like I'm pretty sure I could bang out a quick script that will run this 1000, or 10,000 times, or however many you want, and the observed results will be 50% and not 66%.

Edit: Huh, I'll be damned, it is coming out 66%

"Fungible" is misleading. There are 3 boxes, therefore each box has 1/3 of the possible outcomes. If you start with that, everything else falls into place.

function randint(n) {
	return Math.floor(Math.random()*n);
}

function draw_twice() {
	let boxes = [[0,0],[0,1],[1,1]];
  let box = boxes[randint(3)];
  let first_coin = randint(2);
  let second_coin = 1 - first_coin;
  if (box[first_coin] == 1) {
  	return box[second_coin];
  } else return -1;
}

cases = [0,0,0];
for (let i = 0; i < 10000; i++) {
	cases[draw_twice()+1]++;
}
console.log('Silver picked first: '+cases[0]+' times, gold->silver: '+cases[1]+' times, gold->gold: '+cases[2]+' times');

Console output:

"Silver picked first: 4893 times, gold->silver: 1731 times, gold->gold: 3376 times"

Note that if I drew the coin with box.pop(), I'd get 50% because I'd only be drawing the gold coin from [0,1] every time.

Yeah, mine was a bit different.

class box
{
    public bool[] coins = new bool[2];
}
class Program
{
    static void Main(string[] args)
    {
        box[] boxes = new box[3] { new box(), new box(), new box()};
        boxes[0].coins[0] = true;
        boxes[0].coins[1] = true;
        boxes[1].coins[0] = true;
        boxes[1].coins[1] = false;
        boxes[2].coins[0] = false;
        boxes[2].coins[1] = false;

        int discard_count = 0;
        int firstcoin_count = 0;
        int secondcoin_count = 0;

        Random rand = new Random();

        for(int i = 0; i < 100000; i++)
        {
            int boxnum = rand.Next(0, 3);
            int coinnum = rand.Next(0, 2);

            bool firstcoin = boxes[boxnum].coins[coinnum];
            if (firstcoin)
            {
                firstcoin_count++;
                bool secondcoin = boxes[boxnum].coins[(coinnum + 1) % 2];
                if (secondcoin)
                {
                    secondcoin_count++;
                }
            } else
            {
                discard_count++;
            }
        }
        Console.WriteLine(string.Format("discard_count = {0}", discard_count));
        Console.WriteLine(string.Format("firstcoin_count = {0}", firstcoin_count));
        Console.WriteLine(string.Format("secondcoin_count = {0}", secondcoin_count));
        Console.WriteLine(string.Format("chance of second coin given first coin = {0}", (double)secondcoin_count / (double)firstcoin_count));
    }

With output of

discard_count = 49935

firstcoin_count = 50065

secondcoin_count = 33440

chance of second coin given first coin = 0.6679316888045541