login
A037834
a(n) = Sum_{i=1..m} |d(i) - d(i-1)|, where Sum_{i=0..m} d(i)*2^i is the base-2 representation of n.
21
0, 1, 0, 1, 2, 1, 0, 1, 2, 3, 2, 1, 2, 1, 0, 1, 2, 3, 2, 3, 4, 3, 2, 1, 2, 3, 2, 1, 2, 1, 0, 1, 2, 3, 2, 3, 4, 3, 2, 3, 4, 5, 4, 3, 4, 3, 2, 1, 2, 3, 2, 3, 4, 3, 2, 1, 2, 3, 2, 1, 2, 1, 0, 1, 2, 3, 2, 3, 4, 3, 2, 3, 4, 5, 4, 3, 4, 3, 2, 3, 4, 5, 4, 5, 6, 5, 4, 3, 4, 5, 4, 3, 4, 3, 2, 1, 2, 3, 2, 3
OFFSET
1,5
COMMENTS
Number of i such that |d(i) - d(i-1)| = 1, where Sum_{i=0..m} d(i)*2^i is the base-2 representation of n.
a(n)+1 is the number of iterations of the map x -> A035327(x) needed to reach 0 (see A005811(n) for n>=1). - Flávio V. Fernandes, Apr 28 2025
a(n) is the number of bit transitions (changes between 0 and 1) in the binary representation of the integer n. - Andres Cicuttin, Apr 26 2026
FORMULA
a(n) = A005811(n)-1.
MAPLE
A037834 := proc(n)
local dgs ;
dgs := convert(n, base, 2);
add( abs(op(i, dgs)-op(i-1, dgs)), i=2..nops(dgs)) ;
end proc: # R. J. Mathar, Oct 16 2015
# Alternative:
a:= n-> add(i, i=Bits[Split](Bits[Xor](n, iquo(n, 2))))-1:
seq(a(n), n=1..100); # Alois P. Heinz, Apr 27 2026
MATHEMATICA
Table[Total@ Flatten@ Map[Abs@ Differences@ # &, Partition[ IntegerDigits[n, 2], 2, 1]], {n, 90}] (* Michael De Vlieger, May 09 2017 *)
(* Alternative: *)
a[n_] := Total@ Abs@ Differences@ IntegerDigits[n, 2]; (* Andres Cicuttin, Apr 26 2026 *)
PROG
(Haskell)
a037834 n = sum $ map fromEnum $ zipWith (/=) (tail bs) bs
where bs = a030308_row n
-- Reinhard Zumkeller, Feb 20 2014
(Python)
def A037834(n): return (n^(n>>1)).bit_count()-1 # Chai Wah Wu, Jul 13 2024
CROSSREFS
KEYWORD
nonn,base,easy
STATUS
approved