OFFSET
0,3
COMMENTS
This is an instance of entanglement permutation, where complementary pair A005843/A005408 (even and odd numbers respectively) is entangled with complementary pair A117967/A117968 (positive and negative part of inverse of balanced ternary enumeration of integers, respectively), with a(0) set to 0 and a(1) set to 1.
LINKS
FORMULA
PROG
(Scheme, with memoizing definec-macro from Antti Karttunen's IntSeq-library)
(definec (A246209 n) (cond ((<= n 1) n) ((odd? n) (A117968 (A246209 (/ (- n 1) 2)))) ((even? n) (A117967 (+ 1 (A246209 (/ n 2)))))))
(Python)
from sympy.ntheory.factor_ import digits
def a004488(n): return int("".join(str((3 - i)%3) for i in digits(n, 3)[1:]), 3)
def a117968(n):
if n==1: return 2
if n%3==0: return 3*a117968(n//3)
elif n%3==1: return 3*a117968((n - 1)//3) + 2
else: return 3*a117968((n + 1)//3) + 1
def a117967(n): return 0 if n==0 else a117968(-n) if n<0 else a004488(a117968(n))
def a(n): return n if n<2 else a117967(1 + a(n//2)) if n%2==0 else a117968(a((n - 1)//2))
print([a(n) for n in range(101)]) # Indranil Ghosh, Jun 07 2017
CROSSREFS
KEYWORD
nonn
AUTHOR
Antti Karttunen, Aug 19 2014
STATUS
approved