<jupyter_start><jupyter_text>ActivityTry to write the code to answer the followingquestion.  Feel free to work in small groups.Players A, B, and C play a card game. The rules of the game areas follows:* Player A always plays first.* Player A draws a card. If it is a king, the game ends and A wins.* Otherwise, B draws next. If B draws a Queen or King, the game ends and B  wins.* Otherwise, C draws next. If C draws a Jack, Queen, or King, the game ends  and C wins.* If the game is still going, A plays again and can win with a 10 or higher  (10, J, Q, K).* The game continues cycling in this manner until a player wins.* Aces are low (an ace is a 1)* The drawing is done without replacementPlayer A wins 12 out of 20 games. Should we believe that A is stacking thedeck?Try writing pseudocode (or actual code) that would answer this question.Start by assuming you have a function that plays a round of the game(you can always write this function later).Feel free to work alone or split into small groups.If you're stuck, just ask!<jupyter_code>'''






















'''
import matplotlib.pyplot as plt
import numpy as np


plt.figure()
all_wins = []
'''
This cell gives the function we need to simulate the game.
'''
from random import shuffle


def play_rounds(n_rounds):
    total_wins = 0
    for i in range(n_rounds):
        deck = list(range(1, 14))*4  # represent each card by a number
        shuffle(deck)
        
        card = -1
        min_winning_card = 14
        current_player = 2
        # keep going as long as the last card drawn was too small to win
        while card < min_winning_card:
            card = deck.pop()  # remove a card from the deck
            min_winning_card -= 1  # the value needed to win decreases each round
            current_player = (current_player + 1) % 3
        if current_player == 0:
            total_wins += 1
    return total_wins<jupyter_output><empty_output><jupyter_text>The next few cells show how to build up a histogram of results.You don't really need to do this, but it can be interesting to see what you are working with.<jupyter_code>n_rounds_per_trial = 20

wins = play_rounds(n_rounds_per_trial)
all_wins.append(wins)

bins = np.arange(0, 15 + 1.5) - 0.5
plt.hist(all_wins, bins, color='c', edgecolor='k', stacked=True)
plt.gca().set_xticks(bins + 0.5);
plt.gca().set_yticks(np.arange(0, 21, 2));
plt.ylim(0, 20)
plt.xlabel('# wins');
plt.ylabel('# occurences');
n_trials = 10000
n_rounds_per_trial = 20

all_wins = []
for i in range(n_trials):
    wins = play_rounds(n_rounds_per_trial)
    all_wins.append(wins)

bins = np.arange(0, max(all_wins) + 1.5) - 0.5
plt.figure()
plt.hist(all_wins, bins, color='c', edgecolor='k', weights=np.ones_like(all_wins)/len(all_wins))
plt.gca().set_xticks(bins + 0.5);
plt.axvline(12, color='k', linestyle='dashed', linewidth=1);
plt.xlabel('# wins');
plt.ylabel('probability');
print('p = ', np.sum(np.array(all_wins) >= 12)/n_trials)<jupyter_output><empty_output><jupyter_text>The code snippet below is all we really need to run once we've created the function to simulate our scenario.Just like we saw earlier, as long as we can simulate something, all we have to do to perform a hypothesis test is to count.<jupyter_code>n_trials = 10000
n_rounds_per_trial = 20

count = 0
for i in range(n_trials):
    wins = play_rounds(n_rounds_per_trial)
    if wins >= 12:
        count += 1

print('p = ', count/n_trials)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09716599190283401, 'fraction_numerical': 0.0205320994794679, 'mean_word_length': 3.674324324324324, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 15, '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': '107790', 'license': 'MIT', 'n_tokens_mistral': 1215, 'n_tokens_neox': 1107, 'n_words': 436, 'path': 'High-Card.ipynb', 'repo_name': 'bowmanat/stats-example', 'size': '3458'}