OFFSET
1,2
COMMENTS
Self-inverse permutation of the natural numbers.
if n is written in ternary representation, then a(n) is the value after replacing all digits d (but not the leading one) with 2-d.
a(n+1) = a(n)-1 unless n = 3^k - 1 or 2*3^k-1 for some k. - Robert Israel, Feb 28 2023
LINKS
FORMULA
a(n) = A115310(n+1,2).
MAPLE
a:= proc(n) option remember;
3*procname(floor(n/3))+2 - (n mod 3)
end proc:
a(1):= 1: a(2):= 2:
map(a, [$1..100]); # Robert Israel, Feb 28 2023
MATHEMATICA
A115303[n_] := FromDigits[MapAt[2 - # &, IntegerDigits[n, 3], 2;; ], 3];
Array[A115303, 100] (* Paolo Xausa, May 20 2024 *)
CROSSREFS
KEYWORD
AUTHOR
Reinhard Zumkeller, Jan 20 2006
STATUS
approved