# Sequence A160818: Equal to Average of Permutations of its Digits

This sequence, Sloane's A160818, includes numbers like 370, which obey the following relation:

370 = (037 + 073 + 307 + 370 + 703 + 730)/6

The sum consists of all the permutations of the digits 0, 3, and 7. There are 3 digits, so there are 3! (3 factorial) permutations. If two of the digits were identical, some of the permutations would be identical too, but we don't have to worry about that since the answer works out the same either way. Since there are 6 permutations, we take the average by dividing by 6. Since the right side is equal to 370, 370 is a member of the sequence, being equal to the average of all possible permutations of its digits.

This sequence was first pointed out to me by Claudio Meller, who had found the non-repdigit solutions with 3 digits. R. J. Mathar later wrote MAPLE code that checks all numbers and computes the digit sums explicitly (adding together, for example, 120 permutations for each of the 90000 5-digit candidates).

## Optimization

The calculation (and therefore a search for such numbers) can be greatly optimized by noting that the above sum is equivalent to:

(700×2 + 70×2 + 7×2 + 300×2 + 30×2 + 3×2 + 000×2 + 00×2 + 0×2)/6

Here, the "2" factors represent the number of times each digit appears in each place, which is 2! (2 factorial). Cancelling out the "2/6" into "1/3" gives:

(700 + 70 + 7 + 300 + 30 + 3 + 000 + 00 + 0)/3

Now we can combine the terms into repdigits to get:

(777+333+000)/3

Since 0+3+7 = 10, this can be simplified further into (10×111)/3. Looking at the original number, we see that 3 is the number of digits in 370, 10 is the sum of its digits, and 111 is the repunit with 3 digits. Since (10×111)/3=370, we know that 370 is a solution to the original problem.

In the general case, we are computing S×R/N, where N is the
number of digits in the desired solution, S is the sum of its
digits, R=(10^{N})/9 is the length N repunit. Given a digit-sum
S and a number of digits N, compute S×R/N, then add its
digits to see if the result is S. If it is, then S×R/N
is a solution.

Consider a search for 4-digit numbers. S can be anything from 1 (the digit sum of 1000) to 36 (the digit sum of 9999). Thus, we have to check 36 cases of S×R/N to find all 4-digit solutions. Similarly, we need to check 45 cases for 5-digit solutions, 54 cases for 6 digits, and so on. The only real difficulty is in the need to use a large number of digits for the calculation of S×R/N.

The C source code shown below readily produces the terms of sequence A160818 up to 17 digits:

1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 111, 222, 333, 370, 407, 444, 481, 518, 555, 592, 629, 666, 777, 888, 999, 1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888, 9999, 11111, 22222, 33333, 44444, 55555, 66666, 77777, 88888, 99999, 111111, 222222, 333333, 370370, 407407, 444444, 481481, 518518, 555555, 592592, 629629, 666666, 777777, 888888, 999999, 1111111, 2222222, 3333333, 4444444, 5555555, 6666666, 7777777, 8888888, 9999999, 11111111, 22222222, 33333333, 44444444, 55555555, 66666666, 77777777, 88888888, 99999999, 111111111, 222222222, 333333333, 370370370, 407407407, 444444444, 456790123, 469135802, 481481481, 493827160, 506172839, 518518518, 530864197, 543209876, 555555555, 592592592, 629629629, 666666666, 777777777, 888888888, 999999999, 1111111111, 2222222222, 3333333333, 4444444444, 5555555555, 6666666666, 7777777777, 8888888888, 9999999999, 11111111111, 22222222222, 33333333333, 44444444444, 55555555555, 66666666666, 77777777777, 88888888888, 99999999999, 111111111111, 222222222222, 333333333333, 370370370370, 407407407407, 444444444444, 481481481481, 518518518518, 555555555555, 592592592592, 629629629629, 666666666666, 777777777777, 888888888888, 999999999999, 1111111111111, 2222222222222, 3333333333333, 4444444444444, 5555555555555, 6666666666666, 7777777777777, 8888888888888, 9999999999999, 11111111111111, 22222222222222, 33333333333333, 44444444444444, 55555555555555, 66666666666666, 77777777777777, 88888888888888, 99999999999999, 111111111111111, 222222222222222, 333333333333333, 370370370370370, 407407407407407, 444444444444444, 481481481481481, 518518518518518, 555555555555555, 592592592592592, 629629629629629, 666666666666666, 777777777777777, 888888888888888, 999999999999999, 1111111111111111, 2222222222222222, 3333333333333333, 4444444444444444, 5555555555555555, 6666666666666666, 7777777777777777, 8888888888888888, 9999999999999999, 11111111111111111, 22222222222222222, 33333333333333333, 44444444444444444, 55555555555555555, 66666666666666666, 77777777777777777, 88888888888888888, 99999999999999999, ...

## Notable Terms

After the repdigits, all of which have the property for trivial reasons, the first non-trivial terms are the 3-digit numbers 370, 407, 481, 518, 592, and 629. These are all multiples of 37, and they have this property for reasons that are related to 37 being a factor of 999. The 3-digit repunits 111, 222, 333 and so on are also multiples of 37.

All 6 of the special 3-digit solutions show up again as 6-digit solutions: 370370, 407407, 481481, 518518, 592592, 629629, then again as 9-digit solutions, and so on.

However, in the 9-digit solutions we also have several new ones. 456790123 and 543209876 have a rather nifty pattern of ascending (or descding) digits.

Then we have 469135802, 493827160, 506172839, and 530864197. If you put "0." in front of each of these, they are approximations to various multiples of 1/81, fractions that all have a 9-digit repeating decimal: 38/81 = 0.469135802469135..., 40/81=0.493827160493827... and so on. Noting this, we see that the pretty 9-digit solutions are also related to multiples of 1/81: 37/81=0.4567901234567... and 44/81 = 0.5432098765432...

Note that the deniminator 81 of the fractions we have just noted is
9×9. Looking back at the 3-digit solutions, we can see that they are
also related to fractions with 27 in the denominator:
10/27=0.370370..., 11/27=0.407407..., etc. And of course, the
repunits are related to the fractions 1/9=0.1111...,
2/9=0.2222..., and so on. So, without exception, all of the members
of this sequence shown here (that is, up to less than 10^{17}) can be
connected to the decimal expansion of a rational fraction with a
multiple of 9 in the denominator.

Even larger solutions, up to 84 digits long, were found by H. v.
Eitzen. Several of these, starting with 485596707818930041152263374,
are related to multiples of 1/243:
118/243=0.485596707818930041152263374485596707... and similar
relations to 119/243, 121/243, 122/243, 124/243, and 125/243. Each of
these solutions has 27 digits. The last one
(125/243) is special in a particular
way: it is 5^{3}/3^{5}.

Finally, Eitzen also found six different 81-digit solutions like 495198902606310013717421124828532235939643347050754458161865569272976680384087791, which have the same digits the fractions 361/729, 362/729, 364/729, 365/729, 367/729, and 368/729. Note that 729 = 243×3 = 81×9. Based on this, it is reasonable to hypothesize that all the fractions related to terms in this sequence have powers of 3 in the denominator.

It is also interesting to note that each time a new "family" of
solutions is found, there are 6 of them, and each time the number of
digits is 3 times as great as the number of digits in the most complex
set found up to that point. The numerators are all of the form
(3^{i}±k/2), where k is 1, 5 or 7. For example, when i=6,
we have (3^{6}-7/2)=361, which is one of the numerators of the 729
fractions. The solutions mentioned above all fit into this pattern:

i | solutions |

1 | 1/3 2/3 |

2 | 1/9 2/9 4/9 5/9 7/9 8/9 |

3 | 10/27 11/27 13/27 14/27 16/27 17/27 |

4 | 37/81 38/81 40/81 41/81 43/81 44/81 |

5 | 118/243 119/243 121/243 122/243 124/243 125/243 |

6 | 361/729 362/729 364/729 365/729 367/729 368/729 |

The following C code was used to generate the terms above:

typedef long long s64; /* "long long" is 64-bit on most modern compilers, "lomg" will work is compiling for 64-bit target */ int s64_digsum(s64 n) { s64 t, k10, div, digit; int sum; k10 = 10; div = k10; while (div <= n) { div = div * k10; } div = div / k10; t = n; sum = 0; while (t > 0) { digit = t / div; t = t - (div * digit); sum = sum + digit; div = div / k10; } return(sum); } s64 s64_repunit(int n) { s64 t, sum, k10; int i; k10 = 10; sum = 0; t = 1; for(i=0; i<n; i++) { sum = sum + t; t = t * k10; } return(sum); } /* Generates a B-file for OEIS */ void prop370() { S64 r1, r2; int n, s, lim, t, index; n = 1; lim = 17; index = 0; while(n <= lim) { /* digit-sum can be anything from 1 to 9*n */ for(s=1; s<=9*n; s++) { r1 = s64_repunit(n) * ((s64) s); r2 = r1 / ((s64) n); t = s64_digsum(r2); if (t == s) { if (r2 * ((s64) n) == r1) { /* For reasons that I haven't bothered to prove, the solutions happen to come out in the exact order we want -- no sorting is required. */ index++; printf("%d %lld\n", index, r2); } } } n++; } }Some other sequences are discussed here.

This page was written in the "embarrassingly readable" markup language RHTF, and was last updated on 2022 Mar 28. s.30