A037870 a(n) = (1/2)*Sum{|d(i)-e(i)|}, where Sum{d(i)*2^i} is base 2 representation of n and e(i) are digits d(i) in nonincreasing order, for i=0,1,...,m.
0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 2, 1, 1, 0, 1, 1, 1, 1, 2, 1, 1, 1, 2, 2, 2, 1, 2, 1, 1, 0, 1, 1, 1, 1, 2, 1, 1, 1, 2, 2, 2, 1, 2, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0, 1, 1, 1, 1, 2, 1, 1, 1, 2, 2, 2, 1, 2, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 1, 3, 2, 2
Offset: 1
Links
- Philippe Beaudoin, Table of n, a(n) for n = 1..10000
Programs
-
Maple
a:= proc(n) local L,m; L:= convert(n,base,2); m:= convert(L,`+`); m - convert(L[1..m],`+`); end proc: seq(a(n),n=1..100); # Robert Israel, Aug 20 2014
-
Mathematica
A037870[n_] := Total[Abs[# - Sort[#]]/2] & [IntegerDigits[n, 2]]; Array[A037870, 100] (* Paolo Xausa, Mar 07 2025 *)
-
PARI
a(n) = {d = binary(n); e = vecsort(d); sum(i=1, #d, abs(d[i]-e[i]))/2;} \\ Michel Marcus, Aug 20 2014
Extensions
Definition swapped with A037879. - R. J. Mathar, Oct 19 2015
Comments