OFFSET
0,2
COMMENTS
Take D(n) = {multiset of the nonzero ternary digits of n}, and order those sets by size then by number of 2's, and then a(n) is the index of D(n) among those sets starting from D(0) (the empty set) as index 1.
Such a multiset can be formed by sorting nonzero digits as a "key" value A038574(n) and considering those in numerical order, so that a(n) is the index of A038574(n) among distinct values which occur there: those being A023745.
This is the restricted growth sequence transform of that key A038574, so can be defined as the lexicographically earliest infinite sequence where a(i) = a(j) if and only if A038574(i) = A038574(j). [There are several other such sequences, see the crossrefs section.]
The "triangular" ordering of the multisets allows a direct calculation from the digits of n.
Any additional 0 digits in n have no effect so for instance a(3*n) = a(n).
Any re-ordering of digits in n has no effect, so that for instance arranging terms in a multi-dimensional array of side 3^k is symmetric in that it's unchanged by permuting coordinates.
LINKS
Antti Karttunen, Table of n, a(n) for n = 0..19682 (first 10000 terms from Yunus Selimov)
EXAMPLE
n = 886 = ternary 1012211 has s=6 and t=2 for a(886) = 24; the multiset is D(n) = {1,1,1,1,2,2} and A038574(n) = 111122.
Terms for n=0..8 arranged as a 3 X 3 array show symmetry in transposing X,Y (swap the two least significant ternary digits in n),
1 2 3
2 4 5
3 5 6
MATHEMATICA
A387188[n_] := PolygonalNumber[Count[#, _?Positive]] + Count[#, 2] + 1 & [IntegerDigits[n, 3]];
Array[A387188, 100, 0] (* Paolo Xausa, Nov 14 2025 *)
PROG
(Python)
def a(n):
s=0; t=0
while n:
n, r=divmod(n, 3)
s += (r>=1)
t += (r==2)
return s*(s+1)//2 + t + 1
(PARI) a(n) = my(v=digits(n, 3), s=hammingweight(v), t=vecsum(v)-s); s*(s+1)/2 + t + 1; \\ Kevin Ryde, Oct 21 2025
CROSSREFS
KEYWORD
AUTHOR
Yunus Selimov, Aug 21 2025
STATUS
approved
