I'm trying to work out how many possible 5 digit sequences there are using the numbers $\{1, 2, 3, 4\}$ in which each number appears at least once.
I thought it might be $4\times 3\times 2\times 1\times 4$ but it's not one of the possible answers.
I'm trying to work out how many possible 5 digit sequences there are using the numbers $\{1, 2, 3, 4\}$ in which each number appears at least once.
I thought it might be $4\times 3\times 2\times 1\times 4$ but it's not one of the possible answers.
If it was a $4$-digit number, no problem: we have $4$ numbers, for places and it's permutations, so we have $4!$.
Since we want 5 digits, one of them should be doubled. So we need to choose which digit appears twice ($4$ options), and then arrange them ($5!$ options). However, the internal permutations of the doubled digit do not matter, so each number was counted twice and we divide by $2!$.
Total: $\tfrac{4\cdot 5!}{2!}$
Here's an alternative approach via inclusion-exclusion, where the four properties to be avoided are that $j\in\{1,2,3,4\}$ does not appear: \begin{align} \sum_{k=0}^4 (-1)^k \binom{4}{k} (4-k)^5 &= \binom{4}{0} 4^5 - \binom{4}{1} 3^5 + \binom{4}{2} 2^5 - \binom{4}{3} 1^5 + \binom{4}{4} 0^5 \\ &= 1024 - 972 + 192 - 4 + 0 \\ &= 240 \end{align} More generally, the number of surjections from an $n$-set onto an $m$-set is $$\sum_{k=0}^m (-1)^k \binom{m}{k} (m-k)^n$$