Sum of all $4$-digit numbers that can be formed with the digits $0,1,2,3$

We'll find sums at each place (units, tens, etc.) and add them.

At thousands place each of $1,2,3$ occurs $6$ times. Sum is $6(1+2+3)\cdot 1000=36000$.

For hundreds place, we first look at numbers with thousands digit $1$. These are six numbers in which each of $2,3,0$ occurs twice. Hence in the $18$ nos, each of $1,2,3$ occurs $4$ times while $0$ occurs $18-3\cdot 4=6$ times as expected. Sum at hundreds place is $4(1+2+3)\cdot 100=2400$.

Sum at tens and units places are similar - $240$ and $24$ respectively.

Desired sum is $36000+2400+240+24=38664$.


The repetition case is exactly similar and probably easier.

We have $3\cdot 4^3$ nos in all, with $4^3$ starting with $1,2,3$ each. Sum at thousands place is $4^3(1+2+3)\cdot 1000$

For hundreds place, lets fix any digit as $$\square \, 0 \, \square \, \square$$ There'll be $3\cdot 4^2=48$ occurences of the fixed digit. Thus sum at hundreds place is $48(0+1+2+3)\cdot 100$.

Similarly at tens and units place - $48(0+1+2+3)\cdot 10$ and $48(0+1+2+3)\cdot 1$ resp.

Desired sum is $$(1+2+3)(64000 + 48\cdot 111) = 415968$$