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.

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