0
$\begingroup$

If I have all the combinations of 3 digits (000 to 999) I want to count how many results contain the digit 4:

456
104
404
...

For 4XX there are 100, for X4X it gets hard to calculate and they will be collide with the hundreds, so I totally don't know how to proceed.

$\endgroup$

1 Answer 1

1
$\begingroup$

For $4??$, $?4?$ and $??4$ you'll have exactly the same amount of possibilities. But note that codes like $44?$ will get counted multiple times this way. A more proper way to count is to see that $$\binom 31 \cdot 9^2 + \binom 32 \cdot 9^1 + \binom 33 \cdot 9^0\\ =3\cdot 81 + 3\cdot 9 + 1\cdot 1 = 271$$ Will get the desired result (why?)


Efficient enumeration would find them as follows:

4[^4][^4] -> 81
[^4]4[^4] -> 81
[^4][^4]4 -> 81
44[^4]    -> 9
4[^4]4    -> 9
[^4]44    -> 9
444       -> 1
-----------------
Total        271

[^4] denotes any non-4 digit (9 total).

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .