I've been working through Sedgewick and Flajolet's Analytic Combinatorics and am stuck on a particular problem:
III.21. After Bhaskara Acharya (circa 1150AD). Consider all the numbers formed in decimal with digit 1 used once, with digit 2 used twice, $\dots$, with digit 9 used nine times. Such numbers all have 45 digits. Compute their sum $S$ and discover, much to your amazement, that $S$ equals 4587555960000615321908476928639999999999999999541244403999938467809152 30713600000. This number has a long run of nines. Is there a simple explanation?
I reasoned that, by grouping terms into groups of size 45 where there is one number with a 1 as the $k^{th}$ digit, two numbers with a 2 as the $k^{th}$ digit, etc. the expected value of the $k^{th}$ digit of $S$ is $(1^2 + 2^2 + \ldots + 9^2)/(1+2+\ldots+ 9 = \frac{285}{45}=\frac{19}{3})$. The number of terms in the sum is $\binom{45}{1,2,\ldots,9}$, so $S = \frac{19}{3}(1+10+\ldots+10^{45})\binom{45}{1,2,\ldots,9} = \frac{19}{3}(\frac{10^{46}-1}{9})\binom{45}{1,2,\ldots,9}$, which checks. But I have no idea where to go from here - the problem is in the chapter on multivariate generating functions, but I don't know how I could use those to find a particular string of 9's in the 10-ary expansion of a number.
Not a generating function approach, but I would just calculate how many numbers there are. The digits will appear in their proper proportion ($\frac 1{45} 1's, \dots \frac 9{45} 9's$), so if there are $N$ numbers the sum will be $\frac N{45}(1^2+2^2+\dots 9^2)(\frac {10^{45}-1}9)$ where the last factor is the number with $45\ 1's$
To evaluate $N$, we can choose where the $9's$ go in $45 \choose 9$ ways, where the $8's$ then go in $36 \choose 8$ ways and so on. So we have $N={45 \choose 9}{36 \choose 8}{28 \choose 7}\dots {1 \choose 1}$ and the total sum is$$\frac 1{45}{45 \choose 9}{36 \choose 8}{28 \choose 7}\dots {1 \choose 1}\frac {9\cdot 10\cdot 19}6(\frac {10^{45}-1}9)=\\\frac 1{45}\cdot 65191584694745586153436251091200000\cdot 285(\frac {10^{45}-1}9)=\\45875559600006153219084769286399999999999999954124440399993846780915230713600000$$ This is not going to give a nice explanation of the run of nines.