How many numbers are there between 99 and 1000, having at least one of their digits 7

combinatorics

First of all, from 99 to 1000, we have 100 to 999, meaning $9*10*10$ since 1 to 9 is 9 numbers. We have 900 numbers.
Then, to get all numbers with at least one $7$ in their digits, we can do: All numbers – all numbers with no $7$ at all.
This means, $(9*10*10)-(9*9*9)$ which is $171$.

Apparently, the answer is wrong. It is $252$, performing $(9*10*10)-(9*9*8)$ instead.
Why did we choose $8$ at the end? Aren't there 9 numbers for each three placeholders, by excluding $7$?

Best Answer

If the digit $7$ does not appear in a three-digit number, then the hundreds digit cannot be either $0$ or $7$, so there are eight choices for the hundreds digit. The only restriction on the tens digit is that it is not a $7$, so there are nine choices for the tens digit. Similarly, since the only restriction on the units digit is that is not a $7$, there are also nine choices for the units digit. Thus, there are $8 \cdot 9 \cdot 9$ three-digit positive integers which do not contain the digit $7$. Consequently, there are $$9 \cdot 10 \cdot 10 - 8 \cdot 9 \cdot 9 = 252$$ three-digit positive integers which contain at least one $7$ among its digits.