I need to find the number of $7$s if we write all the numbers from $1$ to $1000000$(so $77$, for example, counts as two $7$s and not one).
Here's what I did:
I split the problem into $7$ sections:
The number of $7$s in numbers with one seven: $\displaystyle \binom{7}{1}$$*$ $9^6$(number of ways to place one $7$ times the number of possible numbers we could make with each displacement. Note that leading zeros wouldn't be a problem since they would result in numbers with less than $7$ digits which we need)
The number of $7$s in numbers with two sevens: $\displaystyle\binom{7}{2} * 9^5 * 2$(same logic, but we multiplied it by $2$ since there's two sevens)
...
So my answer would be $\sum_{i=1}^7 \displaystyle \binom{7}{i}9^ii$ but my textbook says the right answer is $600000$. I do understand its solution but I don't know why mine is wrong.
Thanks in advance!
You're counting $7$ digit numbers but you only need $6$.