%I #23 Nov 11 2023 00:14:43
%S 0,0,0,0,0,0,0,0,0,1,0,1,2,3,4,5,6,7,8,2,1,0,1,2,3,4,5,6,7,3,2,1,0,1,
%T 2,3,4,5,6,4,3,2,1,0,1,2,3,4,5,5,4,3,2,1,0,1,2,3,4,6,5,4,3,2,1,0,1,2,
%U 3,7,6,5,4,3,2,1,0,1,2,8,7,6,5,4,3,2,1,0,1,9
%N Greatest digit of n - least digit of n.
%C a(n) = A054055(n)-A054054(n); a(A010785(n)) = 0; for k>0: a(n) = a(n*10^k + A000030(n)) = a(n*10^k + A010879(n)) = a(n*10^k + A054054(n)) = a(n*10^k + A054055(n)) . - _Reinhard Zumkeller_, Dec 14 2007; corrected by _David Wasserman_, May 21 2008
%H R. Zumkeller, <a href="/A037904/b037904.txt">Table of n, a(n) for n = 1..10000</a>
%p f:= n -> (max-min)(convert(n,base,10)):
%p map(f, [$1..1000]); # _Robert Israel_, Jul 07 2016
%t f[n_] := Block[{d = IntegerDigits[n]}, Max[d] - Min[d]]; Table[ f[n], {n, 1, 15}]
%o (Haskell)
%o a037904 = f 9 0 where
%o f u v 0 = v - u
%o f u v z = f (min u d) (max v d) z' where (z', d) = divMod z 10
%o -- _Reinhard Zumkeller_, Dec 16 2013
%o (PARI) a(n)=my(d=digits(n)); vecmax(d)-vecmin(d) \\ _Charles R Greathouse IV_, Feb 07 2017
%o (Python)
%o def A037904(n): return int(max(s:=str(n)))-int(min(s)) # _Chai Wah Wu_, Nov 10 2023
%Y Cf. A040163, A064834.
%K nonn,base,nice
%O 1,13
%A _Clark Kimberling_
%E Incorrect comments deleted by _Robert Israel_, Jul 07 2016