(./)

[[attachment:rb090822.csv]]

A slightly different appoach delivers a faster and leaner verb.
Within comb2 the items of k in reversed order are the nub of the elements in the corresponding columns of the combinations.
Successive values of z are the size t combinations of (-d+t){ i.#y , boxed according to the leading digit, for t = >:i.x .

comb2=: 4 : 0               NB.    All size x  combinations of y
 d=. x-~#y
 k=. |.(>:d),\y 
 z=. (d$<i.0 0),<i.1 0
 for_j. k  do. z=. j ,.&.> ,&.>/\. z end.
 ; z
)

   [d=.4-~#i.6
2
   [k=. |.(>:2),\i.6
3 4 5
2 3 4
1 2 3
0 1 2

   ] z0=. (d$<i.0 0),<i.1 0
┌┬┬┐
││││
└┴┴┘
   $&.> z0
┌───┬───┬───┐
│0 0│0 0│1 0│
└───┴───┴───┘

   [z1=: j ,.&.> ,&.>/\. z0[j=.0{k
+-+-+-+
|3|4|5|
+-+-+-+
   [z2=: j ,.&.> ,&.>/\. z1[j=.1{k
+---+---+---+
|2 3|3 4|4 5|
|2 4|3 5|   |
|2 5|   |   |
+---+---+---+
   [z3=: j ,.&.> ,&.>/\. z2[j=.2{k
+-----+-----+-----+
|1 2 3|2 3 4|3 4 5|
|1 2 4|2 3 5|     |
|1 2 5|2 4 5|     |
|1 3 4|     |     |
|1 3 5|     |     |
|1 4 5|     |     |
+-----+-----+-----+
   [z4=: j ,.&.> ,&.>/\. z3[j=.3{k
+-------+-------+-------+
|0 1 2 3|1 2 3 4|2 3 4 5|
|0 1 2 4|1 2 3 5|       |
|0 1 2 5|1 2 4 5|       |
|0 1 3 4|1 3 4 5|       |
|0 1 3 5|       |       |
|0 1 4 5|       |       |
|0 2 3 4|       |       |
|0 2 3 5|       |       |
|0 2 4 5|       |       |
|0 3 4 5|       |       |
+-------+-------+-------+


     5 ts'10 comb 20'
0.07020081 24965376
   5 ts'10 comb2 i.20'
0.059551496 12481792

   10 ((comb2 i.)-: comb)20
1

RE Boss/MyNewPage (last edited 2010-08-09 17:38:07 by RE Boss)