Sum of all numbers that can be made out of a set of digits with possibly many duplicates The problem goes as follows, let $S$ be a set of nonzero digits, with possibly repeating or missing digits. Let $K \geq |S|$, I want to find the sum of all numbers with $K$ or less digits, whose nonzero digits exhaust the set $S$. To elaborate, suppose $K = 3$ and $S = \{1,1\}$. Then the numbers satisfying the criteria are $11,101$ and $110$ so the sum would be $222$.
Now I want to consider large sets of numbers (for programming purposes), denote these by $S = \{d_1,\ldots,d_1,d_2,\ldots,d_2,\ldots d_j,\ldots,d_j\}$. I choose this notation to reflect the fact that there may be multiple duplicates and that not all the digits $1,\ldots, 9$ need to be included in the set.
The way I want to attack this problem is by decomposing the numbers created by the digits into single digits numbers. I tried the following approach but I am not sure it is right: Extend the set $S$ by $K - |S|$ zeroes. Then using the elements in $S$ we can create exactly 
$$ \frac{K!}{m_0!m_1!\cdots m_9!}$$
numbers, where $m_j$ denotes the multiplicity of $d_i$ in $S$. Now of these numbers, the fraction $ m_i / K$ will have $d_i$ as the last digit, and for the other digits the fraction is the same. Thus the total sum should be
$$ \frac{K!}{m_0!m_1!\cdots m_9!} \cdot \underbrace{11 \ldots 11}_{k \ \text{times}} \cdot \sum\limits_{i=0}^9 d_i \frac{m_i}{K}.$$
The $\underbrace{11 \ldots 11}_{k \ \text{times}}$ reflects the sum of the weights the digits have at all possible positions.
In the example I showed we would have $S = \{1,1,0\}$ and $K = 3$, giving the total sum of
$$\frac{3!}{0!2!}\cdot 111 \cdot \left( 1 \cdot \frac{2}{3} \right) = 222,$$
which is correct. The formula can be rewritten as 
$$ \frac{(K-1)!}{(K-|S|)!m_1!\cdots m_9!} \cdot \underbrace{11 \ldots 11}_{k \ \text{times}} \cdot \sum S.$$
I wrote a small algorithm that implements this method of calculating the sum as well as a brute force implementation but the numbers do not seem to  match. The motivation I give above for the formula is not really rigorous, especially the part about the fraction of all numbers that have $d_i$ as a certain digit. So is my reasoning correct? Thanks!

I think your argument is correct. As a "Gedankenexperiment" assume that you have $k:=|K|$ different digits, among them $|S|-k$ tiny ones. Then you can form exactly $k!$ different words from these digits. You may consider  the envisaged sum as an expectation. Due to linearity and symmetry you obtain exactly what you have set up.
If, in reality, the digits are not all different then each word has been counted as many times as your correcting fraction indicates.
