OFFSET
1,3
COMMENTS
LINKS
Rémy Sigrist, Table of n, a(n) for n = 1..10459
Rémy Sigrist, PARI program
EXAMPLE
The first terms, alongside the corresponding digit average, are:
n a(n) Digit average
-- ---- -------------
1 0 0
2 1 1
3 2 2
4 3 3
5 4 4
6 5 5
7 6 6
8 7 7
9 8 8
10 9 9
11 10 1/2
12 12 3/2
13 14 5/2
14 16 7/2
15 18 9/2
MATHEMATICA
kmax=7000; avg={}; list={}; For[k=0, k<=kmax, k++, mn=Mean[IntegerDigits[k]]; If[!MemberQ[avg, mn], AppendTo[avg, mn]; AppendTo[list, k]]]; list (* Stefano Spezia, Sep 07 2024 *)
PROG
(PARI) avg(n, base = 10) = { my (d = digits(n, base)); vecsum(d) / max(1, #d) }
{ V = Map(); k = 0; for (n = 0, 6999, v = avg(n); if (!mapisdefined(V, v), mapput(V, v, n); print1 (n", "); ); ); }
(PARI) \\ See Links section.
(Python)
from math import gcd
from itertools import count, islice
def agen():
m = 0
yield 0
for w in count(1): # w = number of digits
for s in range(1, 9*w+1): # s = sum of digits
if gcd(s, w) == 1:
d, r = [1] + [0 for _ in range(w-1)], s-1
for k in range(w-1, -1, -1):
d[k], r = d[k] + min(r, 9), r - min(r, 9)
yield int("".join(map(str, d)))
print(list(islice(agen(), 54)))
# Michael S. Branicky, Sep 08 2024 after Rémy Sigrist PARI in link
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Rémy Sigrist, Sep 04 2024
STATUS
approved