OFFSET
0,3
COMMENTS
LINKS
FORMULA
MATHEMATICA
Module[{nn = 6, s}, s = Flatten[Table[Range[2^(n + 1) - 1, 2^n, -1], {n, 0, nn}]]; Map[If[# == 0, 0, s[[#]]] &, Table[Fold[BitXor, n, Quotient[n, 2^Range[BitLength[n] - 1]]], {n, 0, 2^nn}]]] (* Michael De Vlieger, Apr 06 2017, after Harvey P. Dale at A054429 and Jan Mangaldan at A006068 *)
PROG
(R)
maxrow <- 8 # by choice
a <- 1:3
for(m in 0:maxrow) for(k in 0:(2^m-1)){
a[2^(m+2)+ k] <- a[2^(m+1)+ k] + 2^(m+1)
a[2^(m+2)+ 2^m+k] <- a[2^(m+1)+2^m+k] + 2^(m+1)
a[2^(m+2)+2^(m+1)+ k] <- a[2^(m+1)+2^m+k] + 2^(m+2)
a[2^(m+2)+2^(m+1)+2^m+k] <- a[2^(m+1)+ +k] + 2^(m+2)
}
(a <- c(0, a))
# Yosu Yurramendi, Apr 05 2017
(R)
# Given n, compute a(n) by taking into account the binary representation of n
maxblock <- 7 # by choice
a <- 1
for(n in 2:2^maxblock){
ones <- which(as.integer(intToBits(n)) == 1)
nbit <- as.integer(intToBits(n))[1:tail(ones, n = 1)]
anbit <- nbit
for(k in 2^(0:floor(log2(length(nbit)))) )
anbit <- bitwXor(anbit, c(anbit[-(1:k)], rep(0, k))) # ?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, May 29 2021
(Python)
from sympy import floor
def a006068(n):
s=1
while True:
ns=n>>s
if ns==0: break
n=n^ns
s<<=1
return n
def a054429(n): return 1 if n==1 else 2*a054429(floor(n/2)) + 1 - n%2
def a(n): return 0 if n==0 else a054429(a006068(n)) # Indranil Ghosh, Jun 11 2017
CROSSREFS
KEYWORD
nonn
AUTHOR
Antti Karttunen, Dec 18 2013
STATUS
approved