%I #33 Feb 07 2019 04:16:44
%S 0,1,8,7,59,47,369,247,1469,247,1469,147,13569,17,135689,2,1355780,1,
%T 12446689,0,12446689,1
%N Least nonnegative difference between two numbers whose digits are all taken from a cumulative list of n mod 10 (see example).
%C No prepended 0 admitted.
%C If we start from 1 the sequence is 1, 1, 9, 7, 69, 47, 469, 247, 2469, 247, 2469, 47, ...
%H _Robert Israel_, <a href="/A317231/a317231.txt">List of the first 51 terms in even positions</a>
%F a(2*k+1) >= a(2*k+1+20*j), with k and j >= 0;
%F a(20*k+19) = 0, with k >= 0.
%e [0] -> a(0) = 0.
%e [0,1] -> a(1) = 1 - 0 = 1.
%e [0,1,2] -> a(2) = 10 - 2 = 8.
%e [0,1,2,3] -> a(3) = 20 - 13 = 7.
%e [0,1,2,3,4] -> a(4) = 102 - 43 = 59.
%e [0,1,2,3,4,5] -> a(5) = 301 - 254 = 47.
%e [0,1,2,3,4,5,6] -> a(6) = 1023 - 654 = 369.
%e [0,1,2,3,4,5,6,7] -> a(7) = 4012 - 3765 = 247.
%e [0,1,2,3,4,5,6,7,8] -> a(8) = 10234 - 8765 = 1469.
%e [0,1,2,3,4,5,6,7,8,9] -> a(9) = 50123 - 49876 = 247.
%e [0,1,2,3,4,5,6,7,8,9,0] -> a(10) = 100234 - 98765 = 1469.
%e [0,1,2,3,4,5,6,7,8,9,0,1] -> a(11) = 150023 - 149876 = 147.
%e [0,1,2,3,4,5,6,7,8,9,0,1,2] -> a(12) = 1001223 - 987654 = 13569.
%e a(20) = 12446689 = 10001223344 - 9988776655. - _David A. Corneth_, Jul 26 2018
%p with(numtheory): with(combinat): P:=proc(q)
%p local a,b,c,d,f,i,j,m,n,p,k,s,x,y,w,z;
%p a:=[0,1]; print(0); print(1); for n from 2 to q do b:=10^20;
%p a:=[op(a),n mod 10]; c:=ceil(nops(a)/2); d:=choose(a,c);
%p for k from 1 to nops(d) do x:=permute(d[k]);
%p for j from 1 to nops(x) do f:=a; for m from 1 to nops(x[j]) do
%p for p from 1 to nops(f) do if f[p]=x[j][m] then
%p f:=subsop(p=NULL,f); break; fi; od; od; y:=0;
%p for i from 1 to c do y:=10*y+x[j][i]; od; z:=permute(f);
%p for i from 1 to nops(z) do w:=0; for s from 1 to nops(z[i]) do
%p w:=10*w+z[i][s]; od;
%p if y-w>0 and ilog10(y)+1=c and ilog10(w)+1=nops(a)-c and y-w<b then b:=y-w; fi; od; od; od; print(b); od; end: P(10);
%K nonn,base,more
%O 0,3
%A _Paolo P. Lava_, Jul 24 2018
%E a(13)-a(15) from _Giovanni Resta_, Jul 25 2018