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

combinatorics

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.

Thanks for your time.

Best Answer

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$