A random number generator prints out a sequence of integers \(I_1, I_2, I_3, \dots\). Each integer is independently equally likely to be any one of \(1, 2, \dots, n\), where \(n\) is fixed. The random variable \(X\) takes the value \(r\), where \(I_r\) is the first integer which is a repeat of some earlier integer. Write down an expression for \(\mathbb{P}(X=4)\).
Find an expression for \(\mathbb{P}(X=r)\), where \(2\le r\le n+1\). Hence show that, for any positive integer \(n\),
\[
\frac 1n + \left(1-\frac1n\right) \frac 2 n +
\left(1-\frac1n\right)\left(1-\frac2n\right) \frac3 n + \cdots \ = \ 1
\,.
\]
Write down an expression for \(\mathbb{E}(X)\). (You do not need to simplify it.)
Write down an expression for \(\mathbb{P}(X\ge k)\).
Show that, for any discrete random variable \(Y\) taking the values \(1, 2, \dots, N\),
\[
\mathbb{E}(Y) = \sum_{k=1}^N \mathbb{P}(Y\ge k)\,.
\]
Hence show that, for any positive integer \(n\),
\[
\left(1-\frac{1^2}n\right) +
\left(1-\frac1n\right)\left(1-\frac{2^2}n\right) +
\left(1-\frac1n\right)\left(1-\frac{2}n\right)\left(1-\frac{3^2}n\right)
+ \cdots \ = \ 0.
\]
A positive integer with \(2n\) digits (the first of which must not be \(0\)) is called a balanced number if the sum of the first \(n\) digits equals the sum of the last \(n\) digits.
For example, \(1634\) is a \(4\)-digit balanced number, but \(123401\) is not a balanced number.
Show that seventy \(4\)-digit balanced numbers can be made using the digits \(0, 1, 2, 3\) and \(4\).
Show that \(\frac16 {k \left( k+1 \right) \left( 4k+5 \right) }\) \(4\)-digit balanced numbers can be made using the digits \(0\) to \(k\).
You may use the identity $\displaystyle \sum _{r=0}^{n} r^2 \equiv \tfrac{1}{6} {n \left( n+1 \right)
\left( 2n+1 \right) } \;$.
Solution:
For each number from \(1\) to \(8\) (4+4), we can count the number of ways it can be achieved in any way, or without including a leading \(0\).
\begin{array}{c|c|c|c}
\text{total} & \text{ways with }0 & \text{ways without } 0 & \text{comb}\\ \hline
8 & 1 & 1 & 1\\
7 & 2 & 2 & 4 \\
6 & 3 & 3 & 9 \\
5 & 4 & 4 & 16 \\
4 & 5 & 4 & 20 \\
3 & 4 & 3 & 12 \\
2 & 3 & 2 & 6 \\
1 & 2 & 1 & 2 \\ \hline
&&& 70
\end{array}
For \(2k\) to \(k+1\) there are \(1 \times 1 + 2 \times 2 + \cdots i\times i+\cdots + k\times k\) ways to achieve this, (we can choose anything from \(k\) to \(k-i+1\) for the first digit, and we can never have a \(0\).
For \(1\) to \(k\) we can have \(1 \times 2 + 2 \times 3 + \cdots + k \times (k+1)\) since we cannot start with a \(0\), but can have anything less than or equal to \(i\) for the first digit, and then with the \(0\) we can have the same thing starting with \(0\).
Hence the answer is:
\begin{align*}
&& S &= \sum_{i=1}^k i^2 + \sum_{i=1}^k i (i+1) \\
&&&= 2\sum_{i=1}^k i^2 + \sum_{i=1}^k i \\
&&&= \frac{1}{3} k(k+1)(2k+1) + \frac12k(k+1) \\
&&&= k(k+1) \left (\frac{2k+1}{3} + \frac{1}{2} \right) \\
&&&= \frac16 k(k+1)(4k+2+3) \\
&&&= \frac16 k(k+1)(4k+5)
\end{align*}