cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

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.

This page as a plain text file.
%I A037870 #39 Mar 07 2025 03:50:03
%S A037870 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,
%T A037870 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,
%U A037870 1,1,1,2,2,2,1,2,1,1,1,2,2,2,2,2,2,2,1,3,2,2
%N 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.
%C A037870 a(n) is also the minimum number of bit swap operations that needs to be performed to pack all the bits of n to the right. - _Philippe Beaudoin_, Aug 20 2014
%C A037870 a(n) = 0 if A243109(n) = n; 1 + a(A243109(n)) otherwise. - _Philippe Beaudoin_, Aug 20 2014
%C A037870 The index of the k-th record of this sequence is A020522(k) and corresponds to k ones followed by k zeros. - _Philippe Beaudoin_, Aug 20 2014
%H A037870 Philippe Beaudoin, <a href="/A037870/b037870.txt">Table of n, a(n) for n = 1..10000</a>
%p A037870 a:= proc(n) local L,m;
%p A037870 L:= convert(n,base,2);
%p A037870 m:= convert(L,`+`);
%p A037870 m - convert(L[1..m],`+`);
%p A037870 end proc:
%p A037870 seq(a(n),n=1..100); # _Robert Israel_, Aug 20 2014
%t A037870 A037870[n_] := Total[Abs[# - Sort[#]]/2] & [IntegerDigits[n, 2]];
%t A037870 Array[A037870, 100] (* _Paolo Xausa_, Mar 07 2025 *)
%o A037870 (PARI) a(n) = {d = binary(n); e = vecsort(d); sum(i=1, #d, abs(d[i]-e[i]))/2;} \\ _Michel Marcus_, Aug 20 2014
%Y A037870 Cf. A007088, A020522, A243109.
%K A037870 nonn,base
%O A037870 1,12
%A A037870 _Clark Kimberling_
%E A037870 Definition swapped with A037879. - _R. J. Mathar_, Oct 19 2015