# Counting outcomes from arrangements of 4 bags

I'm having issues solving an introdutory exercise in a probability course. The following problem description is similar but not equal to the one I'm solving. I will first state the problem, then I will describe my solution so far.

Consider a collection of 12 colored and numbered balls in 4 bags. In each bag, there are 3 balls of a single color, each one with a different type. There are 4 available colors (Red (R), Green (G), Blue (B), Yellow (Y)) and 3 available types (Big (b), Medium (m), Small (s)). Each ball is defined by its color and type (e.g. a big red ball (R,b)). The content of each bag is

bag 1: { (R,b), (R,m), (R,s) }

bag 2: { (G,b), (G,m), (G,s) }

bag 3: { (B,b), (B,m), (B,s) }

bag 4: { (Y,b), (Y,m), (Y,s) }

We draw 5 consecutive times from this collection without replacement and keep track of the order of each ball in the sequence.

Let $C_k$ denote the event that exactly k yellow balls are extracted from the collection.

We want to find the probabilities for $C_0$, $C_1$, $C_2$ and $C_3$. Note that this set of events defines a partition for the sample space.

First, we want to know how many outcomes there are. Taking into account that we are concern with the order of the extracted balls, the number of outcomes can be obtained through the following permutation formula

$\sideset{^n}{} P_r = \frac{n!}{(n-r)!}$

For $n=12$ and $r=5$, we have

$\sideset{^{12}}{} P_5 = \frac{12!}{(12-5)!} = \frac{12!}{7!} = 95040$

So, the size of the sample space is 95040 ($|S| = 95040$).

A simple way to determine the number of outcomes in $C_0$ is to use the same permutation formula but with $n=9$ and $r=5$

$\sideset{^9}{} P_5 = \frac{9!}{(9-5)!} = \frac{9!}{(4)!} = 15120$

Meaning that

$P(C_0) = \frac{|C_0|}{|S|} = \frac{15120}{95040} = 0.15909$

But what about the remaining events? My thought process was the following: for each $C_k$, we extract $k$ balls from the fourth bag and extract the remaing $5-k$ from the other bags. Taking into consideration that the order matters, I tried to use two permutations like this:

$|C_k| = \sideset{^3}{} P_{k} * \sideset{^9}{} P_{5-k}$

Using that formula, I end up with the following values:

$|C_0| = \sideset{^3}{} P_{0} * \sideset{^9}{} P_{5-0} = 15120$

$|C_1| = \sideset{^3}{} P_{1} * \sideset{^9}{} P_{5-1} = 9072$

$|C_2| = \sideset{^3}{} P_{2} * \sideset{^9}{} P_{5-2} = 3024$

$|C_3| = \sideset{^3}{} P_{3} * \sideset{^9}{} P_{5-3} = 432$

And the sum of the events' sizes gives me

$\sum_{k=0}^{3} |C_k| = 27648$

Meaning my solution is wrong (the sum is not equal to $|S|$). After concluding that I was wrong, I noticed that my formula has the assumption that the yellow balls always come before the other ones. It seems that I need an expression that allows me to express the following extractions:

Let $Y_m$ be a yellow ball extracted and __ a ball of another color.

For $C_1$, we have the outcomes:

Y1 __ __ __ __
__ Y1 __ __ __
__ __ Y1 __ __
__ __ __ Y1 __
__ __ __ __ Y1

For $C_2$, we have the outcomes:

Y1 Y2 __ __ __
Y1 __ Y2 __ __
Y1 __ __ Y2 __
Y1 __ __ __ Y2
__ Y1 Y2 __ __
__ Y1 __ Y2 __
__ Y1 __ __ Y2
__ __ Y1 Y2 __
__ __ Y1 __ Y2
__ __ __ Y1 Y2

And so forth...

So...I have no idea how to model this. That's my main issue.

After discussing this exercise with a friend of mine, we noticed that there was a missing part in the $|C_k|$ formula. If you look at the final part of my initial post, you notice that those lines look like combinations. In this case, they are combinations without repetition.
For $|C_1|$, for each of those lines, we have $\sideset{^3}{} P_{1} * \sideset{^9}{} P_{4}$ outcomes. Following the same pattern, for $|C_2|$, we have $\sideset{^3}{} P_{2} * \sideset{^9}{} P_{3}$ outcomes per line.
$C_k = C^5_k * \sideset{^3}{} P_{k} * \sideset{^9}{} P_{5-k}$
$\sum_{k=0}^{3} |C_k| = 15120 + 45360 + 30240 + 4320 = 95040$