@ R.E. Boss:

Combinations  k mmd n that result in 0=z1 won't work

   5 mmd 13
|domain error: combnu
|   z2=:(z1     combnu>:x)(+/@:{)"1 _|.|:(>:/&i.>:)x

it seems to me that in this case the result is equal to z0:

   z0
0 3 6 9 12

compared with (see hereafter):

   5 mmd17 13
0 3 6 9 12


@ R. Miller:

if you're after a final result then 2-stage filtering seems to be an option:

f1=: (#~ [: (= >./) [: <./"(1) 2 -~/\"1 ])
f2=:(#~ [: (= >./) [: >./"(1) 2 -~/\"1 ])

   f2 f1 3 comb 8
0 3 7
0 4 7

   f2 f1 4 comb 8
0 2 4 7
0 2 5 7
0 3 5 7

compared with R.E. Boss's:

   >{: 4 mmd 8
0 2 4 7
0 2 5 7
0 3 5 7

and J. Randall's:

   k 4 comb 8
0 2 4 7
0 2 5 7
0 3 5 7

Looking @ the differences of the last example:

 <==> all unique permutations of 2 2 3

apply the running sum to these perms with a leading 0:

   0,.+/\"1 perms
0 2 4 7
0 2 5 7
0 3 5 7

-->

mmd17 =: 4 : 0
 ds=. (,(y-1)-+/@:])(x-2) $ y <....@%&<: x
 if. ({.={:) ds do.
   +/\0,ds
 else.
   0,.+/\"1 (|."0 _~ i...@# ) ds
 end.
)

   3 mmd17 8
0 3 7
0 4 7

   4 mmd17 8
0 2 4 7
0 2 5 7
0 3 5 7


different result for:

   k 6 comb 8
0 1 2 3 5 7
0 1 2 4 5 7
0 1 2 4 6 7
0 1 3 4 5 7
0 1 3 4 6 7
0 1 3 5 6 7
0 2 3 4 5 7
0 2 3 4 6 7
0 2 3 5 6 7
0 2 4 5 6 7

compared with:

   >{: 6 mmd 8
   6 mmd17 8
   f2 f1 6 comb 8
0 1 2 3 4 7
0 1 2 3 6 7
0 1 2 5 6 7
0 1 4 5 6 7
0 3 4 5 6 7


Another one:

   k 5 comb 8
0 1 3 5 7
0 2 3 5 7
0 2 4 5 7
0 2 4 6 7

   >{: 5 mmd 8
   f2 f1 5 comb 8
   5 mmd17 8
0 1 2 3 7
0 1 2 6 7
0 1 5 6 7
0 4 5 6 7




-- 
Met vriendelijke groet,
=@@i

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to