Every week, we pick a real-life project to build your portfolio and get ready for a job. All projects are built with ChatGPT as co-pilot!

Start the ChallengeA tech-culture podcast where you learn to fight the enemies that blocks your way to become a successful professional in tech.

Listen the podcastMany historians of probability note the emergence of a theory of probability as linked to humans attempts to understand games of chance. We begin with an early example called Senet that is at least as old as the year 3000 BC. Here, players moves are decided by dropping 4 paddles with two colored faces. The players are allowed to move based on the number of colored paddles that are facing up. Our goal is to explore the likely outcomes of the drops to begin to understand probability.

**PROBLEM**

The table below begins to explore these possible combinations. We will look at further examples with more possible combinations but this will get us started.

sticks | # ways to get 0 white | 1 white | 2 white | 3 white | 4 white | 5 white |
---|---|---|---|---|---|---|

1 | 1 | 1 | na | na | na | na |

2 | 1 | 2 | 1 | na | na | na |

3 | 1 | 3 | 3 | 1 | na | na |

4 | 1 | 4 | 6 | 4 | 1 | na |

5 | ? | ? | ? | ? | ? | ? |

6 | ? | ? | ? | ? | ? | ? |

The example above is one example of a more general kind of distribution of events. We have 4 two-sided sticks, and we will treat these as 4 Bernoulli Trials. To determine the probability of an outcome, we must:

- Count how many ways there are for this specific outcome to occur
- Mutiply this by the probability of successes and failures

As a function, we would have inputs that determine the outcome (success or failure, red or white, heads or tails, etc.), number of successes and failures, and the probability of a success. Below we have the functional form:

$f(k, n, p) = \Pr(k;n,p)=\Pr(X=k)={\binom {n}{k}}p^{k}(1-p)^{n-k}$

We unpack this as follows:

- $\binom {n}{k}$ counts the number of ways an outcome can occur. For example, $\binom{4}{2}$ could be interpreted as how many ways are there to get two white sticks from four total.
- $p^k$ is the probability of a success to the power of the number of successes. For example $\frac{1}{2}^2$ would be interpreted as the probability of getting a white stick twice.
- $(1 - p)^k$ is the probability of a failure $n-k$ times. For example $(1 - \frac{1}{2})^2$ can be interpreted as the probability of a black stick two out of four attempts.

In [ ]:

```
from scipy.special import comb
```

In [ ]:

```
#ways to pick 2 things from 4
comb(4, 2)
```

Out[ ]:

In [ ]:

```
#prob of success to the number of successes
(1/2)**2
```

Out[ ]:

In [ ]:

```
#prob of failures to number of failures
(1/2)**2
```

Out[ ]:

In [ ]:

```
#put it all together
n_choose_k = comb(4, 2)
p_to_the_k = (1/2)**2
one_minus_p_to_the_n_minus_k = (1/2)**2
#probability of getting 2 white sticks from four
n_choose_k*p_to_the_k*one_minus_p_to_the_n_minus_k
```

Out[ ]:

Suppose we instead play the game of Sennet using 5 sticks.

- How many ways are there to get three white sticks?
- What is the probability that we will get three white sticks?
- Suppose we toss 10 coins. How many different outcomes contain exactly three heads?
- Suppose we toss 20 coins. How many different outcomes contain exactly three heads?
- Complete the next two rows of the table for sennet. Do you recognize a pattern?