login
Triangle read by rows in which n-th row gives n smallest numbers with digit sum n.
5

%I #19 Feb 20 2018 07:39:12

%S 1,2,11,3,12,21,4,13,22,31,5,14,23,32,41,6,15,24,33,42,51,7,16,25,34,

%T 43,52,61,8,17,26,35,44,53,62,71,9,18,27,36,45,54,63,72,81,19,28,37,

%U 46,55,64,73,82,91,109,29,38,47,56,65,74,83,92,119,128,137

%N Triangle read by rows in which n-th row gives n smallest numbers with digit sum n.

%H Robert Israel, <a href="/A081926/b081926.txt">Table of n, a(n) for n = 1..10011</a> (first 141 rows, flattened; first 40 rows from T. D. Noe)

%e Triangle starts

%e 1

%e 2 11

%e 3 12 21

%e 4 13 22 31

%e 5 14 23 32 41

%p f:= proc(n) local Res, d, v, count;

%p Res:= NULL; count:= 0;

%p for d from ceil(n/9) while count < n do

%p v:= g(n,d,n-count,1);

%p Res:= Res, op(v);

%p count:= count + nops(v);

%p od:

%p Res

%p end proc:

%p g:= proc(n,d,remain) local rem, Res, j, j0, v;

%p if remain = 0 then return [] else rem:= remain fi;

%p if nargs = 4 then j0:= 1 else j0:= 0 fi;

%p if d = 1 then if n >= j0 and n <= 9 then [n] else [] fi

%p else

%p Res:= NULL;

%p for j from max(j0, ceil(n-9*(d-1))) to min(9,n) while rem > 0 do

%p v:= map(t -> j*10^(d-1)+t, procname(n-j,d-1,rem));

%p Res:= Res, op(v);

%p rem:= rem - nops(v);

%p od;

%p [Res]

%p fi

%p end proc:

%p for i from 1 to 25 do f(i) od; # _Robert Israel_, Feb 19 2018

%t Needs["Combinatorica`"]; Table[Take[Union[Flatten[Table[FromDigits /@ Permutations[PadRight[s, 6]], {s, Partitions[n, 9]}]]], n], {n, 40}] (* _T. D. Noe_, Mar 08 2013 *)

%Y Cf. A081927, A081928.

%K base,easy,nonn,tabl,look

%O 1,2

%A _Amarnath Murthy_, Apr 01 2003