A little math probablility problem.

I was originally planning tomorrow to post the new Perspective Magazine for you to ogle at (distribution on Friday!) but I shall delay that and you shall be rewarded for waiting with a PDF you can download of the magazine. Ooh.

Instead tonight I had some free time (because tomorrow I shall be skiving school spending time productively at home) So I decided to look at an NRICH problem. Yes, that’s right. I was so bored I decided to do math. Edit: Apparently I didn’t notice the star rating system so it seems as though I picked an easy one.

Click to see problem: Succession in Randomia

Let’s consider a probability tree:

Diagram2

… OK. The first thing we notice is that it looks prettier. Let’s see the series for B now: 1/4 + 1/16 + 1/64 + … . This is identical to T. We can do the same for L and say we have 2/8 + 2/32 + 2/128 … which is exactly the same as B and T. Plugging it into a/1-r (r being 1/4) we get 1/3 for all three. Hence we can say that in fact it is a completely unbiased way of choosing a successor.

My answer to that question is therefore: “Yeah they have an equal chance

Well, I wasn’t going to stop here. Why don’t I simulate it? Here is the coding that simulates the situation (the cheapest brute force technique to tackle the problem):

If you don’t know programming, go take a read through the code anyway and see if you can get a grasp of what’s going on :)

<?php
// The number of times each king as won.
$bingo = 0;
$toto = 0;
$lotto = 0;

// How many times we are going to do the crowning ceremony
$ceremonies = 10000;

// Loop through these instructions to carry out the crowning ceremony.
for ($i = 1; $i < $ceremonies+1; $i++)
{
    $win = FALSE; # Nobody has become king yet.
    $oddeven = 1; # Because the first throw is odd. Assume 1 = odd, 0 = even.
    $firsttoss = TRUE; # We are tossing for the first time.

    // This variable is used later to determine which variable $x or $y is
    // reassigned a value and which keeps the previous toss value.
    $a = 0;

    // Keep on tossing the coins until somebody wins the kingdom.
    while ($win == FALSE)
    {
        // Here we only flip one coin, this will alternate between $x and $y.
        // The one ($x or $y) that isn't assigned a new value will retain the
        // previous toss value so we can find out whether or not we have got
        // two HH or TT in a row.
        // Assume H = 1, T = 2
        if ($a == 0) {
            $x = rand(1,2);
            $a = $a + 1;
        } elseif ($a > 0) {
            $y = rand(1,2);
            $a = 0;
        }

        if ($firsttoss == TRUE) {
            // Nobody can win on the first toss.
            $firsttoss = FALSE;
        } else {
            // If it is HH and ODD...
            if ($x == 1 && $y == 1 && $oddeven == 1) {
                // Lotto will become King.
                $lotto = $lotto + 1;

                // Somebody has won the Kingdom.
                $win = TRUE;
            }

            // If it is TT and ODD...
            if ($x == 2 && $y == 2 && $oddeven == 1) {
                // Lotto will become King.
                $lotto = $lotto + 1;

                // Somebody has won the Kingdom.
                $win = TRUE;
            }

            // If it is HH and EVEN...
            if ($x == 1 && $y == 1 && $oddeven == 0) {
                // Bingo will become King.
                $bingo = $bingo + 1;

                // Somebody has won the Kingdom.
                $win = TRUE;
            }

            // If it is TT and EVEN...
            if ($x == 2 && $y == 2 && $oddeven == 0) {
                // Toto will become King.
                $toto = $toto + 1;

                // Somebody has won the Kingdom.
                $win = TRUE;
            }
        }

        // ... If nobody has won anything ...
        if ($win != TRUE) {
            // We flip again, so Odd->Even or Even->Odd.
            if ($oddeven == 0) {
                $oddeven = 1;
            } else {
                $oddeven = 0;
            }
        }
    }
}

// Tell the computer to print out what results we have.
echo 'Bingo: '. $bingo .'<br />';
echo 'Toto: '. $toto .'<br />';
echo 'Lotto: '. $lotto .'<br />';
?>

I ran it and here is an example result I get. Out of 10,000 ceremonies, this is the number of times each king has won:

Bingo: 3322
Toto: 3340
Lotto: 3338

Pretty close, eh?

No related posts.

Leave a Reply