OFFSET
1,2
COMMENTS
The permutation is self-inverse. Except for fixed points 1, 2, 3, 4, 5, 6, 7 it consists completely of 2-cycles: (10,11), (12,13), (14,15), (16,18), (17,19), (20,22), (21,23), (24,26), (25,27), (28,30), (29,31), (32,37), (33,36), (34,39), (35,38), (45,40), ...
LINKS
Yosu Yurramendi, Table of n, a(n) for n = 1..32767
MATHEMATICA
A[n_]:= If[n<4, n, If[EvenQ[n], 2A[n/2] + 1, 2A[(n - 1)/2]]]; a[n_]:= If[n<4, n, If[OddQ[Floor[Log2[n]]], If[EvenQ[n], 2a[n/2], 2a[(n - 1)/2] + 1], If[EvenQ[n], 2a[n/2] + 1, 2a[(n - 1)/2]]]]; Table[a[A[n]], {n, 50}] (* Indranil Ghosh, Mar 21 2017 *)
PROG
(R)
maxrow <- 6 # by choice
a <- 1:7
for(m in 2:maxrow) for(k in 0:(2^m-1)) {
if(m%%2 == 0) {a[2^(m+1)+2*k ] <- 2*a[2^m+k]+1
a[2^(m+1)+2*k+1] <- 2*a[2^m+k] }
else {a[2^(m+1)+2*k ] <- 2*a[2^m+k]
a[2^(m+1)+2*k+1] <- 2*a[2^m+k]+1}
}
a
(PARI)
A(n) = if(n<4, n, if(n%2, 2*A(n\2), 2*A(n/2)+1));
a(n) = if(n<4, n, if(logint(n, 2)%2, if(n%2, 2*a(n\2) + 1, 2*a(n/2)), if(n%2, 2*a(n\2), 2*a(n/2) + 1)));
for(n=1, 50, print1(a(A(n)), ", ")) \\ Indranil Ghosh, Mar 21 2017, modified by Charles R Greathouse IV
CROSSREFS
KEYWORD
nonn
AUTHOR
Yosu Yurramendi, Mar 20 2017
STATUS
approved