login
A153154
Permutation of natural numbers: A059893-conjugate of A006068.
5
0, 1, 3, 2, 7, 4, 5, 6, 15, 8, 9, 14, 11, 12, 13, 10, 31, 16, 17, 30, 19, 28, 29, 18, 23, 24, 25, 22, 27, 20, 21, 26, 63, 32, 33, 62, 35, 60, 61, 34, 39, 56, 57, 38, 59, 36, 37, 58, 47, 48, 49, 46, 51, 44, 45, 50, 55, 40, 41, 54, 43, 52, 53, 42, 127, 64, 65, 126, 67, 124
OFFSET
0,3
COMMENTS
A002487(1+a(n)) = A020651(n) and A002487(a(n)) = A020650(n). So, it generates the enumeration system of positive rationals based on Stern's sequence A002487. - Yosu Yurramendi, Feb 26 2020
FORMULA
From Yosu Yurramendi, Feb 26 2020: (Start)
a(1) = 1, for all n > 0 a(2*n) = 2*a(n) + 1, a(2*n+1) = 2*a(A065190(n)).
a(1) = 1, a(2) = 3, a(3) = 2, for all n > 1 a(2*n) = 2*a(n) + 1, and if n even a(2*n+1) = 2*a(n+1), else a(2*n+1) = 2*a(n-1).
a(n) = A054429(A231551(n)) = A231551(A065190(n)) = A284459(A054429(n)) =
A332769(A284459(n)) = A258996(A154437(n)). (End)
PROG
(R)
maxn <- 63 # by choice
a <- c(1, 3, 2)
#
for(n in 2:maxn){
a[2*n] <- 2*a[n] + 1
if(n%%2==0) a[2*n+1] <- 2*a[n+1]
else a[2*n+1] <- 2*a[n-1]
}
(a <- c(0, a))
# Yosu Yurramendi, Feb 26 2020
(R)
# Given n, compute a(n) by taking into account the binary representation of n
maxblock <- 8 # by choice
a <- c(1, 3, 2)
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
for(i in 2:(length(anbit) - 1))
anbit[i] <- bitwXor(anbit[i], anbit[i - 1]) # ?bitwXor
anbit[0:(length(anbit) - 1)] <- 1 - anbit[0:(length(anbit) - 1)]
a <- c(a, sum(anbit*2^(0:(length(anbit) - 1))))
}
(a <- c(0, a))
# Yosu Yurramendi, Oct 04 2021
CROSSREFS
Inverse: A153153. a(n) = A059893(A006068(A059893(n))).
Sequence in context: A334998 A153151 A175057 * A154438 A354367 A376182
KEYWORD
nonn,base
AUTHOR
Antti Karttunen, Dec 20 2008
STATUS
approved