Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.
%I #12 Apr 30 2024 14:48:47
%S 0,1,2,3,4,5,6,7,8,9,10,15,12,13,14,11,16,17,18,21,20,19,22,23,24,25,
%T 26,27,28,45,30,31,32,33,46,51,36,37,42,39,40,41,38,43,44,29,34,47,48,
%U 49,50,35,52,53,54,63,56,57,66,65,60,61,62,55,64,59,58,67
%N For any n > 0 with leading ternary digit h = A122586(n), reverse digits in blocks in ternary expansion of n where blocks are separated by h's; a(0) = 0.
%C This sequence is a self-inverse permutation of the nonnegative integers.
%C This sequence has infinitely many fixed points (A125292, among others).
%H Rémy Sigrist, <a href="/A372317/b372317.txt">Table of n, a(n) for n = 0..6561</a>
%H <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>
%e For n = 5323: the ternary expansion of 5323 is "21022011", the corresponding leading digit is "2", we have three blocks: "10", "" and "011", their reversals are: "01", "" and "110", so the ternary expansion of a(5323) is "20122110", and a(5323) = 4845.
%o (PARI) a(n, base = 3) = { my (d = digits(n, base), i = 1); for (j = 2, #d+1, if (j==#d+1 || d[i]==d[j], my (ii = i+1, jj = j-1); while (ii < jj, [d[ii], d[jj]] = [d[jj], d[ii]]; ii++; jj--;); i = j;);); fromdigits(d, base); }
%Y See A367307 and A372318 for similar sequences.
%Y Cf. A122586, A125292.
%K nonn,base
%O 0,3
%A _Rémy Sigrist_, Apr 27 2024