How can I count the 1's digits up to 999,999 using combinatorics? The question is

If you were to write out 1,2,3,4....999,999. How many times would you
have to write the number 1? 1=1, 11=2, 1,111=4...and so on.

I know there are other ways to solve it, but I want to solve it using combinatorics and counting the number of ways to fill {XXX,XXX},{XX,XXX},...,{XX},{X} up with the digit 1.
This formula gives the correct answer but I'm not sure why.  It seems unlikely that it would be a coincidence.
$\sum_{k=0}^6 \binom6k * k \space 9^{6-k}$ $ = 600,000$
wolfram alpha
I think this might be the reason this formula works. Begin by choosing k locations in
XXX,XXX
That's $\binom6k$ such as k=2
XX{X,X}XX
Then you multiply by the number of possibilities are each X in order, $9^4$.
So, why is there a k term?
Maybe this is the number of locations in {X,X}.  Maybe the number of places to start filling with 1's.

Some work that seemed to be going in the correct direction. The number isn't too far off.
Treating it as a counting problem.
Again, counting the number of ways to fill XXX,XXX and then XX,XXX and X,XXX and etc.
Add
$\sum \binom6k * 9^{(6-k)}$ where k=1,...,6
$\sum \binom5k * 9^{(5-k)}$ where k=1,...5
$\sum \binom4k * 9^{(4-k)}$
$\sum \binom3k * 9^{(3-k)}$
$\sum \binom2k * 9^{(2-k)}$
$\sum \binom1k * 9^{(1-k)}$
=513240
wolfram alpha
wolfram alpha
 A: Because it doesn't make an impact, let's try to count the number of times $1$ appears in the numbers from $0$ to $999999$.
We can create all $10^6$ numbers by considering all possible ways to assign a digit ($0$ to $9$) to each of the places in $XXXXXX$.
Since $1$ appears in each place $\frac{1}{10}$ of the time, we have that $1$ appears in the $k^\text{th}$ place exactly $\frac{10^6}{10}=10^5$ times.
Since there are $6$ places, we have that $1$ appears $\boxed{6\cdot 10^5}$ times in total.
P.S. There is also a nice sum identity that will help you in your approach
$$\sum_{k=0}^n \binom{n}{k} kb^{n-k}=n(1+b)^{n-1}$$
You can substitute $n=6$ and $b=9$ to get your expression. To prove this, consider the binomial theorem, which states that
$$f(a,b)=(a+b)^n=\sum_{k=0}^n \binom{n}{k} a^kb^{n-k}$$
Take the partial derivative wrt to $a$ to get
$$\frac{\partial f(a,b)}{\partial a}=n(a+b)^{n-1}=\sum_{k=0}^n \binom{n}{k} k a^{k-1} b^{n-k}$$
Now plug in $a=1$ to get
$$n(1+b)^{n-1}=\sum_{k=0}^n \binom{n}{k} k b^{n-k}$$
A: Write out every number from $0$ to $999,999$, using exactly six digits for each number, with leading zeroes if necessary.
Then one in every ten digits is a $1$, by symmetry; and there are 6,000,000 digits in total.
So there are 600,000 $1$'s.
A: Here we give a combinatorial approach in order to answer OPs question. We consider  all $10^6$ words of length $6$ which are built from digits $0,1,\ldots,9$. We are looking for the number of occurrences of $1$ in these words. We represent each word as function
\begin{align*}
f:\{1,2,3,4,5,6\}\to\{0,1,\ldots,9\}
\end{align*}
where the $j$-th position, $1\leq j\leq 6$ of a word is mapped to a digit from $0$ to $9$. We denote with $X$ the set of all these functions:
\begin{align*}
X=\{f:\{1,2,3,4,5,6\}\to\{0,1,\ldots,9\}\}
\end{align*}
Combinatorial approach:

*

*We partition the set of words according to the number of $1$'s they contain. In terms of functions in $X$ we partition $X$ by defining sets $A_k$ with
\begin{align*}
A_k=\{f\in X:\left|f^{-1}(1)\right|=k\}\qquad\qquad 0\leq k\leq 6
\end{align*}
containing functions in $X$ which map precisely $0\leq k\leq 6$ positions from $1,\dots,6$ to the digit $1$. We obtain
\begin{align*}
X&=\dot{\bigcup_{0\leq k\leq 6}} A_k\\
|X|&=\sum_{k=0}^6 \left|A_k\right|=\sum_{k=0}^6\binom{6}{k}9^{6-k}\tag{1}
\end{align*}
The summands of the right-hand side of (1) are $\binom{6}{k}9^{6-k}$ since we have $\binom{6}{k}$ ways to choose $k$ $1$'s from $6$ positions leaving $9^{6-k}$ ways to place $0,2,3,\ldots,9$ to the remaining $6-k$ positions.
Since each function in $A_k$ maps $k$ positions to $1$ we have to take each of them with multiplicity $k$ in order to count the number of $1$s. We so obtain
\begin{align*}
\sum_{k=0}^6 k|A_k|=\color{blue}{\sum_{k=0}^6\binom{6}{k}k9^{6-k}}\tag{2}
\end{align*}

*

*Another way to count the number of $1$ in these words is to consider functions $B_j\subset X$ which map the $j$-th position of a word ($1\leq j\leq 6$) to $1$. We get
\begin{align*}
B_j=\{f\in X: j\in f^{-1}(1)\}\qquad\qquad 1\leq j\leq 6
\end{align*}
We have $|B_j|=10^5$ since besides the $j$-th position which is mapped to $1$, the other $5$ positions can be mapped to  any value from $0,1,\ldots, 9$. Summing up the cardinalities of $B_j, 1\leq j\leq 6$, we get
\begin{align*}
\sum_{j=1}^6 |B_j|=6\cdot 10^5\tag{3}
\end{align*}
Note, the $B_j$ do not partition the set $X$, since positions other than $j$ may also be mapped to $1$.


But since we count each of the functions in $B_j$ just once, we obtain from (2) and (3) the identity
\begin{align*}
\color{blue}{\sum_{k=0}^6\binom{6}{k}k9^{6-k}=6\cdot 10^5}\tag{4}
\end{align*}
We can verify identity (4) algebraically via
\begin{align*}
\color{blue}{\sum_{k=0}^6}\color{blue}{\binom{6}{k}k9^{6-k}}
&=6\sum_{k=1}^6\binom{5}{k-1}9^{6-k}\tag{5.1}\\
&=6\sum_{k=0}^5\binom{5}{k}9^{5-k}\tag{5.2}\\
&=6(9+1)^5\tag{5.3}\\
&\,\,\color{blue}{=6\cdot 10^5}
\end{align*}
and the claim follows.

Comment:

*

*In (5.1) we skip in the right-hand sum the summand with $k=0$ which does not contribute. We also use the binomial identity $k\binom{n}{k}=n\binom{n-1}{k-1}$.


*In (5.2) we shift the index and start with $k=0$.


*In (5.3) we apply the binomial theorem.
