0
$\begingroup$

**A player is randomly dealt a sequence of 13 cards from a deck of 52-cards. All sequences of 13 cards are equally likely. In an equivalent model, the cards are chosen and dealt one at a time. When choosing a card, the dealer is equally likely to pick any of the cards that remain in the deck.

**If you dealt 13 cards, what is the probability that the 13th card is a King?****

Now with the problem with the naive 1/13 is that it does not consider the possibilities that a king is drawn before, as each king drawn will alter the probability?Does it matter how much card we have dealt before? Monte Carlo simulation gives always lower chance then expected

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Probability_to_draw_a_king
{

    class Program
    {

        static void Main(string[] args)
        {
            for (int r = 0; r < 10; r++)
            {
                List<Tuple<int, int>> allCards = new List<Tuple<int, int>>();
                //initiliaze the desk 
                for (int i = 1; i <= 13; i++)
                {
                    for (int z = 1; z <= 4; z++)
                    {
                        Tuple<int, int> temp = new Tuple<int, int>(i, z);
                        allCards.Add(temp);

                    }
                }
                int successEvent = 0;
                Random rnd = new Random(Environment.TickCount);
                int iterations = 100000;//million
                List<Tuple<int, int>> copy = allCards.ToList();
                for (int i = 0; i < iterations; i++)
                {
                    copy = allCards.ToList();
                    for (int z = 1; z <= 12; z++)
                    {

                        bool found = false;
                        int card = rnd.Next(1, 14);
                        int color = rnd.Next(1, 5);
                        Tuple<int, int> tempCard = new Tuple<int, int>(card, color);

                        for (int q = 0; q < copy.Count; q++)
                        {
                            if (copy[q].Item1 == card && copy[q].Item2 == color)
                            {
                                found = true; break;
                            }
                        }
                        //if we havent found it we try one more time untill we find something to remove(z-1)
                        if (found == false)
                        {
                            z-=1;
                            continue;
                        }
                        //if we find the card we remove it
                        else
                        {

                            for (int q = 0; q < copy.Count; q++)
                            {
                                if (copy[q].Item1 == card && copy[q].Item2 == color)
                                {
                                    copy.Remove(allCards[q]);
                                }
                            }
                        }

                    }
                    // pick a card at random
                    int pickACard = rnd.Next(0, copy.Count);

                    if (copy[pickACard].Item1 == 8)
                    {
                        successEvent++;
                    }
                }
                Console.WriteLine("Expected number of occurences over " + iterations + " iterations" +
                    "is " + iterations * 1 / 13 + " . Actual number of occurences " + successEvent);
            }
        }


    }
}
$\endgroup$
  • $\begingroup$ Don't you mean $1/13?$ The thirteenth card is equally likely to be any of $13$ different ranks. $\endgroup$ – saulspatz Feb 28 at 1:55
  • $\begingroup$ fixed it ...... $\endgroup$ – Goking Feb 28 at 1:56
  • $\begingroup$ No, that makes no difference. The theoretical value is $1/13.$ What values does your code produce? $\endgroup$ – saulspatz Feb 28 at 2:04
  • $\begingroup$ little below that. You should consider separately the possibilities of drawing one king before that , 2 or 3 or 0 and weight them $\endgroup$ – Goking Feb 28 at 11:18
  • $\begingroup$ No, you shouldn't; that has no bearing. (Or rather, if you did it correctly, you'd get the same answer.) Suppose the deck is shuffled and the entire deck is dealt out face down. What is the probability that any given card is a King? Clearly $1/13.$ It's true that if you turn up other cards at random the conditional probability that a given card is a King changes, but if you average over all possible ways the other cards could come up, you'll get $1/13.$ $\endgroup$ – saulspatz Feb 28 at 15:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.