%I #21 Jun 27 2023 14:11:31
%S 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 35,44,81,30,31,36,33,34,37,38,41,54,39,40,45,42,43,46,47,50,55,48,49,
%U 56,51,52,59,62,71,82,57,58,63,60,61,64,65,68,83,66,67,72
%N Next larger integer with same sum of digits in base 3 as n.
%C This sequence is the base-3 variant of A057168 (base-2) and of A228915 (base-10).
%C All integers except those in A062318 appear in this sequence.
%H Rémy Sigrist, <a href="/A319021/b319021.txt">Table of n, a(n) for n = 1..10000</a>
%F a(3^k) = 3^(k+1) for any k >= 0.
%F A053735(a(n)) = A053735(n).
%e The first terms, alongside the ternary representations of n and of a(n), are:
%e n a(n) ter(n) ter(a(n))
%e -- ---- ------ ---------
%e 1 3 1 10
%e 2 4 2 11
%e 3 9 10 100
%e 4 6 11 20
%e 5 7 12 21
%e 6 10 20 101
%e 7 11 21 102
%e 8 14 22 112
%e 9 27 100 1000
%e 10 12 101 110
%e 11 13 102 111
%e 12 18 110 200
%e 13 15 111 120
%e 14 16 112 121
%e 15 19 120 201
%t 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 (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 (Python)
%o def a(n, base=3):
%o c, b, w = 0, base, 0
%o while True:
%o d = n%b
%o if d+1 < b and c:
%o return (n+1)*b**w + ((c-1)%(b-1)+1)*b**((c-1)//(b-1))-1
%o c += d; n //= b; w += 1
%o print([a(n) for n in range(1, 67)]) # _Michael S. Branicky_, Jul 10 2022 after _Rémy Sigrist_
%Y Cf. A053735, A057168, A062318, A228915.
%K nonn,base
%O 1,1
%A _Rémy Sigrist_, Sep 08 2018
|