Counting the number of integers with given restrictions

Question: Consider the numbers $$1$$ through $$99,999$$ in their ordinary decimal representations. How many contain exactly one of each of the digits $$2, 3, 4, 5$$?

Answer: $$720$$.

We have two cases: four digit numbers and five digit numbers.

Five digit numbers:

Let $$x \in \{2, 3, 4, 5\}$$. If the first position in a five digit number is not $$x$$, then there are $$5$$ possibilities for this position as there are four values for $$x$$ and $$0$$ is inadmissable. The rest of the four positions will have the various permutations of four values of $$x$$. There are $$5 \times 4!$$ such numbers. If the non-$$x$$ value is in the second position, then there are $$4$$ ways to choose an $$x$$-value for the first position, $$6$$ integers for the second position and $$3!$$ permutations for the rest of the positions. There are $$4\times 6 \times 3!$$ such numbers. If the non-$$x$$ value is in the third position, then there are $$\binom 42$$ ways to choose two $$x$$-values, $$2!$$ ways to permute them and $$6$$ integers for the third position meaning there are $$6 \times 2 \times 6$$ such numbers. When the non-$$x$$ value is in the fourth position, there are $$4 \times 3! \times 6$$ such numbers. Finally, if non-$$x$$ is in the fifth position, there are $$4! \times 6$$ such numbers.

Four digit numbers:

We just need to permute the number $$2345$$. There are $$4!$$ such permutations.

Thus the number of numbers with the given restrictions is $$5\times 4! + 4\times 3!\times 6 + 2\times 6 \times 6 + 4 \times 3! \times 6 + 6 \times 4! + 4! = 648$$.

What did I forget to take into account? Thanks.

• Very nicely thought of answer! But I think you missed one (several) cases in the 5 integer case: There can be 6 options for the non $\;2,3,4,5\;$ digit, as far as its position is not the first one (we count zero here), and there 5 options for that digit if its position is the first one...and etc. – DonAntonio Aug 5 '20 at 15:16

To answer the question you asked: In the case where the non-$$x$$ value is in the third position, you missed permuting the fourth and fifth digits of the number, so that term should be $$6\cdot 2\cdot 6\cdot 2$$ (rather than $$6\cdot 2\cdot 6$$).

Write $$0$$ at the front of four digits number so we always have five digits number. The fifth number is one of $$(0,1,6,7,8,9)$$.

$$6\times 5! =720$$

• Great, concise solution. – Andrew Chin Aug 5 '20 at 15:19

Four digit numbers are accounted for by the $$4!=\underline{24}$$ ways to arrange the four digits $$2,3,4,5$$.
Five digit numbers not containing $$0$$ are accounted for by $$5\times5!=\underline{600}$$ (arranging the four digits $$2,3,4,5$$ then one from $$\{1,6,7,8,9\}$$).
Five digit numbers containing $$0$$ are accounted for by the $$5!-4!=\underline{96}$$ ways to arrange the five digits $$0,2,3,4,5$$ while fixing $$0$$ to the second to fifth digit.

In total, we have $$24+600+96=\boxed{720}$$ as desired.