OFFSET
0,3
LINKS
FORMULA
MATHEMATICA
{0}~Join~Table[1 + BitXor[#, Floor[#/2]] &[BitXor @@ Table[Floor[n/2^m], {m, 0, Floor[Log[2, n]]}] - 1], {n, 81}] (* Michael De Vlieger, Feb 29 2016, after Jean-François Alcover at A006068 and Robert G. Wilson v at A003188 *)
PROG
(PARI)
a003188(n)=bitxor(n, n>>1);
a006068(n)= {
my( s=1, ns );
while ( 1,
ns = n >> s;
if ( 0==ns, break() );
n = bitxor(n, ns);
s <<= 1;
);
return (n);
} \\ by Joerg Arndt
a(n)=if(n==0, 0, 1 + a003188(a006068(n) - 1)); \\ Indranil Ghosh, Jun 07 2017
(Python)
def a003188(n): return n^(n>>1)
def a006068(n):
s=1
while True:
ns=n>>s
if ns==0: break
n=n^ns
s<<=1
return n
def a(n): return 0 if n==0 else 1 + a003188(a006068(n) - 1) # Indranil Ghosh, Jun 07 2017
CROSSREFS
KEYWORD
nonn
AUTHOR
Antti Karttunen, Feb 12 2016
STATUS
approved