login
(1/2)*Sum{|d(i)-e(i)|}, where Sum{d(i)*10^i} is base 10 representation of n and e(i) are digits d(i) in nonincreasing order, for i=0,1,...,m.
2

%I #8 Oct 19 2015 14:33:43

%S 0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,2,1,0,0,0,0,0,0,0,0,3,2,1,0,0,

%T 0,0,0,0,0,4,3,2,1,0,0,0,0,0,0,5,4,3,2,1,0,0,0,0,0,6,5,4,3,2,1,0,0,0,

%U 0,7,6,5,4,3,2,1,0,0,0,8,7,6,5,4,3,2,1,0,0,9

%N (1/2)*Sum{|d(i)-e(i)|}, where Sum{d(i)*10^i} is base 10 representation of n and e(i) are digits d(i) in nonincreasing order, for i=0,1,...,m.

%p A037878 := proc(n)

%p local a,dgs,dgsE ;

%p a := 0 ;

%p dgs := convert(n,base,10);

%p dgsE := sort(dgs,`>`) ;

%p for i from 1 to nops(dgs) do

%p a := a+ abs(op(i,dgs)-op(i,dgsE)) ;

%p end do:

%p a/2 ;

%p end proc: # _R. J. Mathar_, Oct 19 2015

%K nonn,base

%O 1,20

%A _Clark Kimberling_

%E Definition swapped with A037887. - _R. J. Mathar_, Oct 19 2015