arrow_back Powrót do aplikacji

Drawing Cards

INTRODUCTION

A standard deck of cards contains 4 suits (spades, diamonds of hearts and clubs) and 13 face cards (2 – 10, Jack, Queen, King and Ace). This means that there are 52 cards in such a deck.

Card games are usually played with 2, 3 or 4 people. Therefore, you can simulate the random allocation of cards and observe the results obtained.

You can analyze the results as they are displayed, but you can also try to automate this process:

FUN FACT

The probability of drawing a specific card from a full deck is152.

However, if we want to calculate the probability of getting a set of cards, then we have to use more complicated calculations, for example, we have to use combinations of:

$C_{n}^{k}=
\begin{pmatrix}
n\\
k
\end{pmatrix}=\frac{n!}{(n-k)! \cdot k!} $

EXAMPLE:

We will calculate the probability of getting three queens:

  • we pick three cards from the deck, so we have $C_{52}^{3}=
    \begin{pmatrix}
    52\\
    3
    \end{pmatrix}=\frac{52!}{(52-3)! \cdot 3!}=\frac{52\cdot 51\cdot 50\cdot 49!}{49!\cdot 3\cdot 2\cdot 1}=\frac{52\cdot 51\cdot 50}{3\cdot 2\cdot 1} =22100$ possibilities
  • there are four queens in the deck, but we want three, so we have: $C_{4}^{3}=
    \begin{pmatrix}
    4\\
    3
    \end{pmatrix}=\frac{4!}{(4-3)! \cdot 3!}=4$ possibilities
  • the probability of getting three queens from the whole deck is then: $P=\frac{4}{22100}=\frac{1}{5525}$ 

PYTHON CODE

See in Google Colaboratory


HOW THE CODE WORKS?

  • The obtained result can be imported into a spreadsheet and further analyze which cards were drawn:
  • Copy the result by selecting it with the mouse and pressing Ctrl+C
    • Player 1:   ,5♣, 5♦, 2♠, A♣, 6♣, 8♦, K♣, 10♦, J♦, A♠, 4♥, 3♥, A♥, 9♣, K♦, 3♠, Q♥
    • Player 2:   ,9♦, Q♦, J♣, 10♥, 10♣, 4♣, 7♥, 4♠, A♦, 3♣, K♠, 8♠, K♥, 4♦, 6♦, 2♥, 8♣
    • Player 3:   ,8♥, Q♠, 7♣, 10♠, 6♥, 5♥, 9♠, Q♣, 2♦, 9♥, J♠, 5♠, 3♦, 7♠, J♥, 6♠, 2♣
  • Open Google Spreadsheet, you can use sheets.new address
Tu ma być grafika: https://mat.przemek.edu.pl/wp-content/uploads/2024/08/image-4.png
  • Paste the data saved in the clipboard
    • in Edit > Paste Special > Values ​​Only
    • or by pressing Ctrl + Shift + V
Tu ma być grafika: https://mat.przemek.edu.pl/wp-content/uploads/2024/08/image-5.png

To separate tabs into separate cells:

  • in cell B1 adjacent to the first result A1, enter the formula:=split(A1;„,”)
  • then grab the lower right corner of cell B1 in the shape of a blue circle with the mouse
    Tu ma być grafika: https://lh7-rt.googleusercontent.com/docsz/AD_4nXfhp4Yfe7PXgl-AysSzJomn3ku7IMO7BxBP4qEyHyAP02-GZubg5zkS8blgElwUU8yioalWDVe9xGGtDY8ccHv8dH9hRRhGNHJUYYA-Me5IRdqFkSqJQlvY5v2BRQuEB93LCq867rMbgH2V_S1VVHUEHL5p?key=TKd3avrB28G0to2TTxsecw
    and drag down
arrow_back Powrót do aplikacji