# How many numbers of 4 digits have at least three specific digits

The question I tried to solve goes like this:

How many 4-digit numbers have at least one digit $$2$$, one digit $$3$$ and one digit $$4$$?

I saw it as simple as this (because it's exactly 4 digits): The number will have a $$2$$, a $$3$$, a $$4$$ and $$X$$.

So the solution I thought would be is:

$$3 \cdot 2 \cdot 1 \cdot 10 = 60$$

$$X$$ could be any digit of the $$10$$ digits.

However, this also includes numbers that start with $$0$$. This can't count so I remove $$6$$ because of

$$0234,0324,0342,0432,0243,0423$$

so the solution would be $$54$$.

However, this isn't at all the solution. What am I missing?

• Just consider the case $\{2,3,4,X\}$ where $X\notin \{0,2,3,4\}$ . There are $6$ possible choices for $X$ and then $4!=24$ ways to order the four. That gives us $6\times 24$ options which is already much bigger than your answer.
– lulu
Jun 5, 2020 at 11:32

Here is an other way to evaluate the number of possibilities. We will condition on the fourth number we have

Case: $$0$$

If the fourth number is $$0$$, it can't ne in the first position. It has three places where it can go. Next we put the $$4$$ (three remaining places), etc. This gives us $$3\times3\times2\times1=18\tag1$$

Case: $$1,5,6,7,8,9$$

There are six choice for the number and four places to put it. Then, we put the $$4, 3$$ and $$2$$ as before. This gives us $$6\times4\times3\times2\times1=144\tag2$$

Case: $$2,3,4$$

We now have a repeated number. First we chose which one is repeated (three choices) and where to put them, $$4\choose2$$. Finally, we put the remaining numbers. This gives us $$3\times{4\choose2}\times2\times1=36\tag3$$ There are $$18+144+36=198$$ such numbers.

Hope it helps

You could also find the same result starting with you reasoning. Starting with $$3\times2\times1\times10$$ You counted nombre of the form $$3245$$ but not $$5324$$. The fourth digit you chose was always the last digit of the number. You need to add a $$\times4$$ to choose where you put the last digit. $$3\times2\times1\times10\times4=240$$ Now we counted numbers starting with $$0$$, we need to remove them ($$6$$ cases). Also, if the fourth number was a $$2$$, it was counted twice. $$234(2)$$ is the same as $$(2)342$$ where $$(2)$$ represents the fourth digit. So we need to remove the number where the fourth digit is $$2,3$$ or $$4$$. ($$36$$ cases).

This bring us back to $$240-6-36=198$$ possibilities.

The main reason for your original formula being too low is that you do not count the order/the permutations of the last digit. You only account for choosing it.

One way to break it down is that you either have:

• Four distinct digits which then can be ordered in $$4!$$ ways
• Three distinct digits with one digit being repeated twice

The first case is fairly simple, namely the fourth digit should be chosen from the 7 possible digits $$D\setminus\{2,3,4\}=\{0,1,5,6,7,8,9\}$$. This gives you $$7\cdot4!=168$$ possibilities for the first case.

The second case is a bit more elaborate, but still not too bad. One way to do it is to choose the fourth digit from $$\{2,3,4\}$$ and then place the two unique digits. This gives $$3\cdot 4\cdot 3=36$$ possibilities for the second case, namely chose one of three, place first unique digit in one of four places, then place second unique digit in one of three remaining places. The last two places must hold the repeated digit.

A total of $$168+36=204$$ such numbers can be formed. Then you have to discard numbers starting with a leading zero. Those will be $$3!=6$$ so you get down to $$198$$ as a total.

• Yes, I account for choosing them, but each time I choose them in another order. $3 \cdot 2 \cdot 1$ will be the way of choosing $3$ numbers in different orders. That's why I don't understand what's wrong. Jun 5, 2020 at 12:43
• @PichiWuana: You choose those three in different orders, but not the last one which might also be in different orders. An immediate upper bound due to this consideration should be $4\cdot 3\cdot 2\cdot 1\cdot 10=240$ and indeed the solution is slightly less than that. The factor $4$ in the front denotes the number of ways to position the fourth chosen number. Jun 5, 2020 at 12:46
• Ohhhh... I see... Jun 5, 2020 at 12:48

What you're missing is that $$X$$ can also be $$2, 3$$ or $$4$$, and so you'll have counted some of the solutions twice (for example $$2X34$$ and $$X234$$ are the same if $$X = 2$$).

What you should do to fix this is to handle cases; one case for when the number has all digits different, and one case where one of $$2, 3, 4$$ is repeated.

• Ohh I see. But the answer is more than $54$, and with what you say it should be less (because I count twice some numbers) Jun 5, 2020 at 11:29