# Number of four-digit numbers with nonzero leading digit in two ways

We would like to count the number of four-digit numbers such that the leftmost digit is nonzero in which at least two digits are the same.

We want to do this in two ways and compare the results.

First way : complementary set

Total number of four-digit numbers such that the leftmost digit is nonzero :

$$9\times 10^3 = 9000$$

Numbers with pairwaise distint digits :

$$9\times 9 \times 8 \times 7 = 4536$$

So the number of those in which at least two digits are the same is

$$9000 - 4536 = 4464$$

Second way : bruteforce

number of numbers with all digits identical :

$$9$$

number of numbers with three identical digits :

$$4\times 9 \times 8 + 9$$ (case containing $$0$$ and the other case)

number of numbers with two identical digits :

$$6\times 9 \times 8 \times 7 + 3 \times 9 \times 8$$

We we sum this up we get

$$3546$$

I don't see what is my mistake.

• By leading digit is usually meant highest power of 10 like 7 in 7233. Mar 15, 2020 at 6:27
• yes I meant leftmost sorry (edited) Mar 15, 2020 at 6:29

All four digits the same: $$aaaa$$
$$9$$ choices for $$a$$, total numbers: $$1\times 9=9$$

Three digits the same: $$aaab, aaba, abaa, abbb$$
$$9$$ choices for $$a$$ and $$9$$ for $$b$$, total: $$4\times 9\times 9=324$$

Two digits the same, other two distinct: $$aabc, abac, abca, abbc, abcb, abcc$$
$$9$$ choices for $$a$$, $$9$$ for $$b$$ and $$8$$ for $$c$$, total: $$6\times 9\times 9\times 8=3888$$

Two digits the same, other two also same: $$aabb, abab, abba$$
$$9$$ choices for $$a$$ and $$9$$ for $$b$$, total: $$3\times 9\times 9=243$$

Grand total: $$9+324+3888+243=4464$$

Actually, both of your solutions are wrong.

$$9\times9\times8\times7=4536$$ so the number of integers where at least two digits are the same is $$9000-4536=4464$$

Now we know the answer, let's try to enumerate the digits:

number of 4-digit integers with 4 identical digits: $$9$$

number of 4-digit integers with only 3 identical digits: $$9\times4\times8+9+27$$

Because we have $${4 \choose 3}$$ ways to choose positions of our (non-zero) identical digits, times 9 (non-zero digits), times 8 (remaining non-zero digits). You forgot to count $$27$$ additional cases which represent the number of cases where the non-identical digit is $$0$$ (e.g. $$1011$$). This can be calculated as $$9{4 \choose 3} - 9$$ (we subtract 9 for the cases where the integer is of the form $$0xxx$$)

You could also count all the configurations first (including those that start with $$0$$) and then subtract $$9$$ (counted configurations of the form $$0xxx$$) and then $$9{3 \choose 2}$$ (configurations of the form $$0x00$$, $$00x0$$ or $$000x$$). Again you'd find $$10*9*{4 \choose 3} - 9 - 9{3 \choose 2}=324$$ such integers

Following this logic, can you count how many 4-digit integers have only 2 identical digits?

• the statement says "where "at least" two digits are the same " Mar 15, 2020 at 7:05
• @ahmed Yes you're right on the wording, however the answer should be correct (I checked by writing a quick script) Mar 15, 2020 at 7:18
• You're still missing some edge-cases. Where is $1013$ counted? Mar 15, 2020 at 7:39
• I got you thanks Mar 15, 2020 at 7:47
• You're almost there! What about two pairs of two digits like 1001? Mar 15, 2020 at 8:32