<jupyter_start><jupyter_text>A Combination Problem Source: Anita randomly picks 4 cards from a deck of 52-cards and places them back into the deck ( Any set of 4 cards is equally likely ). Then, Babita randomly chooses 8 cards out of the same deck ( Any set of 8 cards is equally likely). Assume that the choice of 4 cards by Anita and the choice of 8 cards by Babita are independent. What is the probability that all 4 cards chosen by Anita are in the set of 8 cards chosen by Babita?(Question 7 from the contest) We can either solve this problem using Monte Carlo simulation or solve it using exact analytical methods.  Monte Carlo Simulation<jupyter_code>import numpy as np
# Define a deck of 52 unique cards
deck = range(1,53)
#print("Deck of cards (from 1 to 52): " + str(deck))

# number of simulation replications/runs
num_reps = int(1e8)

# initialize the counter which counts the number of times all 4 Anita's cards 
# are in the set of 8 cards chosen by Babia
counter = 0

# start the simulation
for rep in range(num_reps):
    # Anita: randomly choose 4 cards from our deck of 52 cards (without replacement).
    Anita_cards = np.random.choice(deck, size=4, replace = False)
    #print("Anita's cards:" + str(Anita_cards))

    # Babita: randomly choose 8 cards from our deck of 52 cards (without replacement).
    Babita_cards = np.random.choice(deck, size=8, replace = False)
    #print("Babita's cards" + str(Babita_cards))
    
    # Check if all 4 cards chosen by Anita are in the of set of 8 cards chosen by Babita
    if set(Anita_cards).issubset(set(Babita_cards)):
        counter+=1
    #print("counter: " + str(counter))

    
# calculate the probability that all 4 cards chosen by Anita are in the of set of 8 cards chosen by Babita
sim_prob = counter/num_reps

# print the results
print("Probability that all 4 cards chosen by Anita are in the of set of 8 cards chosen by Babita is (using Monte Carlo simulation): {0:.6f}".format(sim_prob))<jupyter_output>Probability that all 4 cards chosen by Anita are in the of set of 8 cards chosen by Babita is (using Monte Carlo simulation): 0.000290<jupyter_text>Exact SolutionNow let's calculate the probailities directly using our knowledge of combinatorics. First, we define a function for the mathematical "choose" function, i.e., nCr (n Choose r):$$ \large nCr = \frac{n!}{r! \times (n-r)!} \quad \text{where } 1 \leq r \leq n $$<jupyter_code>import math

def nCr(n,r):
    f = math.factorial
    return f(n) // (f(r) * f(n-r))

# check: nCr(6,2) is 15
nCr(6,2)<jupyter_output><empty_output><jupyter_text>The probability is calculated by dividing the number of combinations that has the desired property (i.e., combinations where the 8 cards that Babita picks includes all 4 cards that Anita has picked) by the total number of combinations that can happen (i.e., all combinations that Babita can pick 8 cards froma the deck).The total number of possible combination would be 52C4 (For selecting 4 cards by Anita) * 52C8 (For selecting 8 cards by Babita).Since, the 4 cards that Anita chooses is among the 8 cards which Babita has chosen, thus the number of combinations possible is 52C4 (For selecting the 4 cards selected by Anita) * 48C4 (For selecting any other 4 cards by Babita, since the 4 cards selected by Anita are common)The solution is:$$ \large{P_{\text{exact method}} = \frac{52C4 \times 48C4}{52C4 \times 52C8}}$$<jupyter_code>prob_exact = (nCr(48,4)/nCr(52,8))
print("Probability that all 4 cards chosen by Anita are in the of set of 8 cards chosen by Babita is (using exact method): {0:.6f}".format(prob_exact))<jupyter_output>Probability that all 4 cards chosen by Anita are in the of set of 8 cards chosen by Babita is (using exact method): 0.000259
{'fraction_non_alphanumeric': 0.0776023548300776, 'fraction_numerical': 0.029435375970029435, 'mean_word_length': 4.347639484978541, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '159719', 'license': 'MIT', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1086, 'n_words': 543, 'path': 'src/a_combination_problem.ipynb', 'repo_name': 'vahidnourbakhsh/Statisitcs', 'size': '3737'}