OFFSET
1,2
COMMENTS
As A258746 the permutation is self-inverse. Except for fixed points 1, 2, 3 it consists completely of 2-cycles: (4,6), (5,7), (8,10), (9,11), (12,14), (13,15), (16,26), (17,27), ..., (21,31), ..., (32,42), ... . - Yosu Yurramendi, Mar 31 2016
When terms of sequence |n - a(n)|/2 (n > 3) are considered only once, and they are sorted in increasing order, A147992 is obtained. - Yosu Yurramendi, Apr 05 2016
LINKS
FORMULA
a(1) = 1, a(2) = 2, a(3) = 3. For n = 2^m + k, m > 1, 0 <= k < 2^m. If m is even, then a(2^(m+1)+k) = a(2^m + k) + 2^m and a(2^(m+1) + 2^m+k) = a(2^m+k) + 2^(m+1). If m is odd, then a(2^(m+1) + k) = a(2^m+k) + 2^(m+1) and a(2^(m+1) + 2^m+k) = a(2^m+k) + 2^m.
From Yosu Yurramendi, Mar 23 2017: (Start)
a(1) = 1, for m >= 0 and 0 <= k < 2^m, a(2^(m+1) + 2*k) = 2*a(2^(m+1) - 1 - k), a(2^(m+1) + 2*k + 1) = 2*a(2^(m+1) - 1 - k) + 1. - Yosu Yurramendi, May 23 2020
PROG
(R)
maxlevel <- 5 # by choice
a <- 1
for(m in 0:maxlevel) for(k in 0:(2^m-1)){
a[2^(m+1) + 2*k ] = 2*a[2^(m+1) - 1 - k]
a[2^(m+1) + 2*k + 1] = 2*a[2^(m+1) - 1 - k] + 1}
a
(R) # Given n, compute a(n) by taking into account the binary representation of n
maxblock <- 7 # by choice
a <- 1:3
for(n in 4:2^maxblock){
ones <- which(as.integer(intToBits(n)) == 1)
nbit <- as.integer(intToBits(n))[1:tail(ones, n = 1)]
anbit <- nbit
anbit[seq(2, length(anbit) - 1, 2)] <- 1 - anbit[seq(2, length(anbit) - 1, 2)]
a <- c(a, sum(anbit*2^(0:(length(anbit) - 1))))
}
a
# Yosu Yurramendi, Mar 30 2021
CROSSREFS
KEYWORD
nonn,look
AUTHOR
Yosu Yurramendi, Jun 16 2015
STATUS
approved