login
In the ternary expansion of n: keep the initial digit, and then replace 0's with 1's and 1's with 0's.
2

%I #17 Jun 02 2024 08:21:51

%S 0,1,2,4,3,5,7,6,8,13,12,14,10,9,11,16,15,17,22,21,23,19,18,20,25,24,

%T 26,40,39,41,37,36,38,43,42,44,31,30,32,28,27,29,34,33,35,49,48,50,46,

%U 45,47,52,51,53,67,66,68,64,63,65,70,69,71,58,57,59,55,54

%N In the ternary expansion of n: keep the initial digit, and then replace 0's with 1's and 1's with 0's.

%C This sequence is a self-inverse permutation of the nonnegative integers.

%H Rémy Sigrist, <a href="/A372783/b372783.txt">Table of n, a(n) for n = 0..6560</a>

%H <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>

%F a(n) = n iff n belongs to A062318.

%e For n = 42: the ternary expansion of 42 is "1120", so the ternary expansion of a(42) is "1021", and a(42) = 34.

%t Table[t3=IntegerDigits[n,3];fd=First[t3];tr=Rest[t3]/.{1->0,0->1};PrependTo[tr,fd];FromDigits[tr,3],{n,0,67}] (* _James C. McMahon_, May 31 2024 *)

%o (PARI) a(n) = { my (t = digits(n, 3)); for (i = 2, #t, t[i] = [1,0,2][1+t[i]];); fromdigits(t, 3); }

%Y Cf. A004488, A062318 (fixed points), A115303.

%K nonn,base,look,easy

%O 0,3

%A _Rémy Sigrist_, May 13 2024