1

A playlist has $10$ songs. Two musics players ($A$ and $B$) implement the "shuffle and repeat" feature a little differently. In $B$, no song will be played twice in a row, but it is possible in $A$. For each music player, find the probability that at least one song is played $3$ or more times before every song is played at least once.


By the pigeonhole principle, all complete playing of the playlist in which no song repeated $3$ times, lasts $10$ to $19$ songs. The approach for $A$ I'm thinking to consider different lengths of a playlist in which it's possible for playlist to finish before a three-peat. The last song to play must play exactly once, and there are $10$ options for the last song. So using permutation with repeats, and considering the number of combinations of songs of a certain length, the number of plays of length $k$ that finishes without a three-peat is

$$n(k) = 10(k-1)!\frac{^9C_{k-10}}{2^{k-10}}$$

with $k-10$ songs played twice. I can normalize everything to $19$ songs, by using $N(k) = n(k)\cdot(10^{19-k})$. My intent is to use $N(k)$ as the number of complement events, for music player $A$. Incidentally, if a song is to play three times before all songs play once, its three times must be within the first 19 songs.

So my answer to part $A$ is $\displaystyle 1 - \frac{\sum_{k=10}^{19}N(k)}{10^{19}} \approx 0.9786$

But I am not sure if that's sound and if there is better method that scales better with the number of songs. I have no idea how to get started with $B$, but I suspect some inclusion-exclusion can be applied, by modifying the solution to $A$.

okzoomer
  • 458

1 Answers1

1

Here is a solution to the problem for music player $A$, using an exponential probability generating function. Readers not familiar with generating functions can find many resources in the answers to this question: How can I learn about generating functions?

Consider the situation just before every song has been played at least once. There is one song that has not been played at all, and all the other songs have been played either one or two times; then on the next play the missing song is played, completing the set. Let's assume for the sake of simplicity that song number $1$ is the song which completes the set, and let $a_n$ be the probability that on the $n$th play (1) song number $1$ has not been played, and (2) all other songs have been played one or two times. The probability that song number $1$ is played on the $(n+1)$th play, completing the set, is then $(1/10)a_n$. The exponential generating function for $a_n$ is $$f(x) = \left( \frac{x}{10} + \frac{1}{2!} \left( \frac{x}{10} \right)^2 \right)^9$$ We would like to know $\sum_{n=0}^{\infty} a_n$ (which is actually a finite sum). We might expand $f(x)$ to do this, but there is a shortcut based on the identity $$\int_0^{\infty} x^n e^{-x} \;dx = n!$$ Because of this identity, $$\sum_{n=0}^{\infty}a_n = \int_0^{\infty} f(x) e^{-x} \;dx$$ The integral evaluates to $0.0213966$. (I admit to using a computer algebra system, but a pencil and paper solution should not be too difficult.) The probability of completing the set with song number $1$ is $(1/10)\sum_{n=0}^{\infty} a_n$. But the assumption that song number $1$ is the missing song was arbitrary, so the probability of a sequence of plays in which every song is played at least once and no song is played more than two times is $$10 \cdot \frac{1}{10} \sum_{n=0}^{\infty} a_n = \sum_{n=0}^{\infty} a_n = \boxed{0.0213966}$$

awkward
  • 15,626
  • So our answers agree, but we arrived at $f(x)$ in different ways. Could you kindly elaborate on how to solve the integral by hand? I am not grasping how the integral is computationally simpler than the series. – okzoomer Jan 24 '22 at 17:20
  • @okzoomer To evaluate the integral by hand, start by expanding $f(x)$ by the Binomial Theorem. You then have a sum of several terms of the form $x^k e^{-x}$ to integrate. – awkward Jan 24 '22 at 18:37