This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.
%I A319021 #21 Jun 27 2023 14:11:31 %S A319021 3,4,9,6,7,10,11,14,27,12,13,18,15,16,19,20,23,28,21,22,29,24,25,32, %T A319021 35,44,81,30,31,36,33,34,37,38,41,54,39,40,45,42,43,46,47,50,55,48,49, %U A319021 56,51,52,59,62,71,82,57,58,63,60,61,64,65,68,83,66,67,72 %N A319021 Next larger integer with same sum of digits in base 3 as n. %C A319021 This sequence is the base-3 variant of A057168 (base-2) and of A228915 (base-10). %C A319021 All integers except those in A062318 appear in this sequence. %H A319021 Rémy Sigrist, <a href="/A319021/b319021.txt">Table of n, a(n) for n = 1..10000</a> %F A319021 a(3^k) = 3^(k+1) for any k >= 0. %F A319021 A053735(a(n)) = A053735(n). %e A319021 The first terms, alongside the ternary representations of n and of a(n), are: %e A319021 n a(n) ter(n) ter(a(n)) %e A319021 -- ---- ------ --------- %e A319021 1 3 1 10 %e A319021 2 4 2 11 %e A319021 3 9 10 100 %e A319021 4 6 11 20 %e A319021 5 7 12 21 %e A319021 6 10 20 101 %e A319021 7 11 21 102 %e A319021 8 14 22 112 %e A319021 9 27 100 1000 %e A319021 10 12 101 110 %e A319021 11 13 102 111 %e A319021 12 18 110 200 %e A319021 13 15 111 120 %e A319021 14 16 112 121 %e A319021 15 19 120 201 %t A319021 nli3[n_]:=Module[{nd3=Total[IntegerDigits[n,3]],k=n+1},While[Total[IntegerDigits[k,3]]!=nd3,k++];k]; Array[nli3,70] (* _Harvey P. Dale_, Jun 27 2023 *) %o A319021 (PARI) a(n, base=3) = my (c=0); for (w=0, oo, my (d=n % base); if (d+1 < base && c, return ((n+1)*base^w + ((c-1)%(base-1) + 1)*base^((c-1)\(base-1))-1), c += d; n \= base)) %o A319021 (Python) %o A319021 def a(n, base=3): %o A319021 c, b, w = 0, base, 0 %o A319021 while True: %o A319021 d = n%b %o A319021 if d+1 < b and c: %o A319021 return (n+1)*b**w + ((c-1)%(b-1)+1)*b**((c-1)//(b-1))-1 %o A319021 c += d; n //= b; w += 1 %o A319021 print([a(n) for n in range(1, 67)]) # _Michael S. Branicky_, Jul 10 2022 after _Rémy Sigrist_ %Y A319021 Cf. A053735, A057168, A062318, A228915. %K A319021 nonn,base %O A319021 1,1 %A A319021 _Rémy Sigrist_, Sep 08 2018