janmr blog

A Sum of All Digit Permutations

Recently, user preshtalwalkar on Twitter posed the following question:

What is the sum of all 5 digit numbers using 1, 2, 3, 4, 5 without repetition?

I will present two solutions: The solution I came up with and a smart one.

My solution: Notice that at each position (the 1's, 10's, 100's, etc.) the sum of the digits is

4!(1+2+3+4+5)=2415=360,4! \cdot (1+2+3+4+5) = 24 \cdot 15 = 360,

since there are 4!4! permutations each time a given digit is fixed. Now, summing up the 1's, 10's, 100's, etc. gives

a5=1360+10360+100360+=11111360=3999960a_5 = 1 \cdot 360 + 10 \cdot 360 + 100 \cdot 360 + \cdots = 11111 \cdot 360 = 3999960

which is the solution.

The smart solution: Note that there are 5!=1205!=120 permutations and at each position the average digit value is 3. Therefore, the answer is

a5=12033333=3999960.a_5 = 120 \cdot 33333 = 3999960.

This is easily generalized to nn-digit numbers, n9n \leq 9, as

an=n+1210n19n!=118(10n1)(n+1)!,a_n = \frac{n+1}{2} \frac{10^n - 1}{9} n! = \tfrac{1}{18} (10^n - 1) (n + 1)!,

since (n+1)/2(n+1)/2 is the average digit value and k=0n110k=(10n1)/9\sum_{k=0}^{n-1} 10^k=(10^n-1)/9, which is a finite sum of a geometric progression. The sequence ana_n is A071268 at OEIS.

We can generalize further if we consider dd-digit numbers using 1,,n1, \ldots, n as the digits, 1dn91 \leq d \leq n \leq 9. We then have

bnd=(10d1)(n+1)!18(nd)!b_{nd} = \frac{(10^d-1)(n+1)!}{18(n-d)!}

where, of course, an=bnna_n=b_{nn}.

Commenting is not possible for this post, but feel free to leave a question, correction or any comment by using the contact page