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)=24⋅15=360,
since there are 4! permutations each time a given digit is fixed.
Now, summing up the 1's, 10's, 100's, etc. gives
a5=1⋅360+10⋅360+100⋅360+⋯=11111⋅360=3999960
which is the solution.
The smart solution:
Note that there are 5!=120 permutations and at each position the average digit value is 3.
Therefore, the answer is
a5=120⋅33333=3999960.
This is easily generalized to n-digit numbers, n≤9, as
an=2n+1910n−1n!=181(10n−1)(n+1)!,
since (n+1)/2 is the average digit value and ∑k=0n−110k=(10n−1)/9,
which is a finite sum of a geometric progression.
The sequence an is A071268 at OEIS.
We can generalize further if we consider d-digit numbers using 1,…,n as the digits,
1≤d≤n≤9. We then have
bnd=18(n−d)!(10d−1)(n+1)!
where, of course, an=bnn.
Commenting is not possible for this post, but feel free to leave a question,
correction or any comment by using the
contact page