A monkey is sitting at a simplified keyboard that only includes the keys “a”, “b”, “c”, and “d”.
The monkey presses the keys at random.
How many sequences are there of length eight that use at most three of the different keys?
I am looking on how to approach this. I have read other posts here with similar problems but some of them have formulas that I have not yet learned.
First we choose the three letters we can use. Then there are $8$ positions. This gives $3^8$ possible strings, multiplied by $4$ ways that we can choose the three letters.
But wait, we counted the same outcomes more than once.
In particular, we counted the two unique letters case twice, and we counted the case with one unique letter three times.
Luckily, it is easier to calculate these probabilities.
The case with one unique letter is simply $4$.
The case with at least two unique letters is ${4 \choose 2} 2^8$, but we have to subtract the one letter case to get exactly two letters. Namely, we count each one letter case three times, so we subtract $12$.
All in all, this gives
$4 \cdot 3^8 - ({4 \choose 2} 2^8 - 12) - 2(4) = 24712$.