cp's OEIS Frontend

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.

A321726 Reverse each run of nonzero digits in ternary expansion of n and convert back to decimal.

This page as a plain text file.
%I A321726 #18 Mar 12 2025 18:42:47
%S A321726 0,1,2,3,4,7,6,5,8,9,10,11,12,13,22,21,16,25,18,19,20,15,14,23,24,17,
%T A321726 26,27,28,29,30,31,34,33,32,35,36,37,38,39,40,67,66,49,76,63,64,65,48,
%U A321726 43,70,75,52,79,54,55,56,57,58,61,60,59,62,45,46,47,42,41
%N A321726 Reverse each run of nonzero digits in ternary expansion of n and convert back to decimal.
%C A321726 This sequence is a self-inverse permutation of nonnegative integers.
%H A321726 Rémy Sigrist, <a href="/A321726/b321726.txt">Table of n, a(n) for n = 0..19683</a>
%H A321726 <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>
%F A321726 a(3 * n) = 3 * a(n).
%e A321726 For n = 3497:
%e A321726 - the ternary representation of 3497 is "11210112",
%e A321726 - we replace "1121" by "1211" and "112" by "211" and obtain "12110211",
%e A321726 - hence a(3497) = 3991.
%t A321726 rernz[n_]:=FromDigits[Flatten[If[FreeQ[#,0],Reverse[#],#]&/@SplitBy[ IntegerDigits[ n,3],#!=0&]],3]; Array[rernz,70,0] (* _Harvey P. Dale_, Nov 15 2020 *)
%o A321726 (PARI) a(n, base=3) = my (d=digits(n*base, base), nz=0); for (i=1, #d, if (d[i], nz++, if (nz, for (j=1, floor(nz/2), [d[i-j],d[i-nz-1+j]] = [d[i-nz-1+j],d[i-j]]); nz=0))); fromdigits(d, base)/base
%Y A321726 See A321464 for a similar sequence.
%K A321726 nonn,base,look
%O A321726 0,3
%A A321726 _Rémy Sigrist_, Nov 17 2018