OFFSET
0,3
LINKS
FORMULA
MATHEMATICA
A003188[n_] := BitXor[n, Floor[n/2]]; A006068[n_] := If[n == 0, 0, BitXor @@ Table[Floor[n/2^m], {m, 0, Floor[Log[2, n]]}]]; a[n_] := If[n == 0, 0, A003188[1 + A006068[n-1]]]; Table[a[n], {n, 0, 100}] (* Jean-François Alcover, Feb 23 2016 *)
PROG
(PARI) A003188(n) = bitxor(n, floor(n/2));
(Python)
def A003188(n): return n^(n//2)
def A006068(n):
if n<2: return n
m = A006068(n//2)
return 2*m + (n%2 + m%2)%2
print([a(n) for n in range(0, 101)]) # Indranil Ghosh, Mar 31 2017
(Python)
def A268717(n):
k, m = n-1, n-1>>1
while m > 0:
k ^= m
m >>= 1
return k+1^ k+1>>1 # Chai Wah Wu, Jun 29 2022
CROSSREFS
KEYWORD
nonn
AUTHOR
Antti Karttunen, Feb 12 2016
STATUS
approved