Find the sum of all 4-digit numbers formed by using digits 0, 2, 3, 5 and 8?

Find the sum of all 4-digit numbers formed by using digits 0, 2, 3, 5 and 8.

Finding the total number of number is possible, but how can the sum be found?


Solution 1:

If you fix 8 as the last digit, you see that there are $4 \cdot 3 \cdot 2$ ways to complete the number. Thus, 8 appears 24 times as the last digit. By the same logic, if we enumerate all possible numbers using these 5 digits, each number appears 24 times in each of the 4 positions. That is, the digit 8 contributes $(24 \cdot 8 + 240 \cdot 8 + 2400 \cdot 8 + 24000 \cdot 8)$. In total, we have $$(0 + 2 + 3 + 5 + 8)(24 + 240 + 2400 + 24000) = 479952$$ as our total sum.

Update: In case 4-digit numbers cannot start with 0, then we have overcounted. Now we have to subtract the amount by which we overcounted, which is found by answering: "What is the sum of all 3-digit numbers formed by using digits 2,3,5, and 8?" Now if 8 appears as the last digit, then there are 6 ways to complete the number, so 8 contributes $(6\cdot 8 + 60 \cdot 8 + 600 \cdot 8)$. In total, we have $$(2 + 3 + 5 + 8)(6 + 60 + 600) = 11988.$$ Subtracting this from the above gives us 467964.

Solution 2:

Total[FromDigits /@ Select[Flatten[Permutations /@ 
 Subsets[{0, 2, 3, 5, 8}, {4}], 1], First[#] =!= 0 &]]

(* Out: 467964 *)

I'm due for some down-votes.