Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Card probability

  1. Mar 15, 2010 #1
    I am trying to understand a general algorithm for calculating the probability of a hand of n cards drawn from a deck containing a given set of cards. Where the given set of cards is n in size it is easy. I am struggling when the number of cards specified is less than n.

    To make it easier to udnerstand I am working with a deck of 12 cards. A,2 and 3 of each suit only.

    For example. From my 12 card deck I draw 4 cards.

    What is the probability at least 1 is a club and at least 1 is a spade.

    The probability that only 1 is a club and only 1 is spade is easy 3c1*3c1*6c2 = 135/12c4

    But the answer is 258/12c4

    The missing 123 are CCCS (3), SSSC (3), CCSS (9), CCSx (54) and SSCx (54) where x is not a C or S.

    Is there a clever formula to count these 123 or do I need to work them out individually as I have above.
  2. jcsd
  3. Mar 17, 2010 #2


    User Avatar

    P(At least one spade and at least club) = 1 - P(no spades U no clubs)

    = 1 - [P(no spades) + P(no clubs) - P(no spades n no clubs) :n represents an intersection]

    In general if you are trying to calculate a probability that involves a large number of events, it is often simpler to evaluate the probability of the complement. Then, using the fact that the probability of the total sample space is equal to 1, the calculation of the original probability becomes equally simple.
    Last edited: Mar 17, 2010
  4. Mar 17, 2010 #3


    User Avatar
    Science Advisor
    Homework Helper

    Hi jav! :smile:

    Please don't give out full answers on this forum …

    your answer would have been good if it had stopped as above.

    (can you edit it?)
  5. Mar 17, 2010 #4


    User Avatar

    Sorry about that tim. Done
  6. Mar 17, 2010 #5
    How do you calc the intersection ?
  7. Mar 17, 2010 #6


    User Avatar
    Science Advisor
    Homework Helper

    uhh?? :confused: P(no spades n no clubs) = P(no black cards)
  8. Mar 17, 2010 #7
    The problem this and all other card probability answers I can find on the web have is they approach each problem as if they are unique problems to solve. In this example you took my example and turned it around to take advantage of a particular aspect of the example without addressing the more fundamental question.

    I am after an algorithm not just an answer.

    As it happens I have managed to work it out. It is elegant quick and reliably calculates the probability of any demand for n cards of a particular suit combinations from a deck in any state. No tricks required.

    I will post some pseudocode tomorrow that shows the algorithm I came up with.

  9. Mar 18, 2010 #8
    The following code is psudocode is based loosely on Java/C#. It would never compile as it assumes some functions that the coder would need to supply but it should give you an idea of the algorithm

    // list_of_desired_suits is an order independent list of the suits we want the drawn cards to have. For example if we want the probability 1 or more clubs then we pass in a list with 1 club. If we want the probability of 2 or more clubs then we pass in a list with 2 clubs. If we want the probability of 5 clubs in 5 drawn cards then we pass in 5 clubs in the list. If we want at least 2 clubs and at least 2 hearts then we pass in 2 clubs and 2 hearts in the list.
    // known_cards is a list of cards we know cant be in the drawn cards. Typically this might be because they are already in our hand or have already been played.
    // drawn_cards is the number of cards being drawn without replacement. If must be at least as large as there are cards in the list_of_desired_suits otherwise the result is 0.0 ... impossible.
    Function GetProbability(list_of_desired_suits, known_cards, drawn_cards)
    numerator = 1; // start with a numerator of 1
    result = 0.0; // start with a probability of 0

    if (count(list_of_desired_suits) > drawn_cards)
    return 0.0; // impossible

    // reduce the desired suits to just the unique ones
    list_of_unique_desired_suits = remove_duplicates(list_of_desired_suits);

    // work out how many cards are in my deck but not one of the desired suits.
    not_in_desired_suits = countcardsindecknotin(list_of_unique_desired_suits);

    // multiply the numerator by the number of combinations of cards in each of the desired suits
    foreach(suit s in list_of_unique_suits)
    numerator = numerator * BinomialCoefficent(countcardsindeckinsuit(s), drawn);

    // multiple the numerator by the number of combinations of cards not in any of the desired suits where the number of cards in list_of_desired_suits is less than the cards drawn.
    ` numerator = numerator * BinomialCoefficient(not_in_desired_suits, drawn - count(list_of_desired_suits));

    // probability of exactly the number of cards of the desired suits being in the drawn cards
    result = numerator / BinomialCoefficient(undealtcards, drawn);

    // now we need to add in the probability that one of the unknown cards is the same suit as our desired cards
    if (count(list_of_desired_suits) < drawn_cards)
    // we need to add the probability of each of the desired suits being in the unknown cards
    foreach(suit s in list_of_unique_desired_suits)
    // create a working copy
    new_list = list_of_desired_suits;

    // add a demand for an extra copy of one of our desired suits

    // recursively call this function to calculate the probability of this more specific desired suits list
    result = result + GetProbability(new_list, known_cards, drawn_cards);

    return result;
  10. Apr 11, 2010 #9
    finf probabilty of following event:
    A king,ace,queen of diamond or jack of clubs appears in drwaing a single card from a well-shuffeled deck of 52 cards.
    i checked it in many guides n books ,,its solve like thz
    King, 4/52+ace 4/52+queen 1/52+ jack 1/52 +10/52 so my question iz that y v have taken 4 king n 4 ace wen itz not given in question???..plzz replyyyyyy
  11. Apr 11, 2010 #10


    User Avatar
    Science Advisor
    Homework Helper

    Welcome to PF!

    Hi ceena bibi! Welcome to PF! :smile:

    Please always start a new thread when asking about a new problem. :wink:

    (and the forum rules forbid the use of abbreviations and slang such as "y v" and "itz")
  12. Apr 11, 2010 #11
    The reason you take 4 kings and 4 aces is because the question does not require them to be of a particular suit. As there are 4 kings in the pack and any of them are good enough the probability of getting a king is 4/52. If you only wanted say the king of clubs then the probability would be 1/52 as there is only one king of clubs in the 52 card pack.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook