OFFSET
0,3
COMMENTS
LINKS
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).
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
KEYWORD
nonn,base
AUTHOR
Antti Karttunen, Dec 20 2008
STATUS
approved