Solved – Probability of drawing a heart and then an even number, without replacement, from a deck of cards

probability

I had an algebra student I know ask me an interesting question: What is the probability of drawing a heart out of a deck of cards, and then drawing an even number right after it?

Clearly, the probability of drawing a heart out of the deck is 13/52, or 1/4. The probability of drawing an even number as card #2 ($c\in\{2,4,6,8,10\}$) for any suit is 20/51, except when the first card drawn is an even heart, then the probability of the second draw is 19/51.

I wish it were as simple as $ P(E|H) = \frac{P(E\cap H)}{P(H)} = \frac{\frac{5}{52}}{\frac{13}{52}} = \frac{5}{13} $.

My Monte Carlo simulation I wrote to simulate this process does not match: I get something in the neighborhood of 9-10% from the code I wrote. Where is my logic faulty?

import java.util.Random;

public class CardCounter {

    /**
     * @param args
     */
    public static void main(String[] args) {
        int heartThenEvenCount = 0;
        int cardsNotEqualCount = 0;

        for(int i = 0; i < 1000000; i++) {
            Random r = new Random();

            int card1 = r.nextInt(51) + 1;
            int card2 = r.nextInt(51) + 1;

            /* Assume that 1-13 are hearts
            Ace = 1
            King = 0
            Queen = 12
            Jack = 11
            Other numbers as they are written on card. */

            //Make sure the cards are not the same
            if(card1 != card2) {
                // Check to see if the first card is a heart.
                cardsNotEqualCount++;
                if(card1 <= 13) {
                    // Check to see if the second card is even, but not a face card.
                    int card2Rank = (card2 % 13); 
                    if(card2Rank > 0 && card2Rank <= 10 && (card2Rank % 2) == 0) {
                        heartThenEvenCount++;
                    }
                }
            }
        }
        System.out.println(heartThenEvenCount + " / " + cardsNotEqualCount);
        System.out.println(heartThenEvenCount/(double)cardsNotEqualCount);
    }
}

Best Answer

I don't know what the heck your "wish it were as simple as" analytical calculation is supposed to be, but you have already laid out the pieces, and just need to combine them properly. Use the law of total probability and break down (condition on) whether the 1st card heart is not an even number or is an even number.

So P(1st card is heart and 2nd card is an even number) = P(1st card is heart and not an even number) * P(2nd card is even number given 1st card is not an even number) + P(1st card is heart and is an even number) * P(2nd card is even number given 1st card is an even number) = $(8/52) (20/51) + (5/52) (19/51) = .0961538...$ which is in the 9 to 10% neighborhood you say your simulation provided.