NB. combination NB. written by SHIMURA Masato //14 July 2010 NB. common util tap=: i.@! A. i. NB. Table of all permutations cp=: {@(,&<) NB. Cartesian products/ 0 1 cp 2 3 4 mean=: +/%# drop_item=: 4 : '( x ~: i. # y) # y' NB. 1 drop_item i.4 NB. -------------------------- take_anypair=: 4 : 0 NB. 3 u 5 /! not i.5 tmp0=., ,./@{ x # < i. y tmp1=. ~. /:~ L:0 tmp0 ((; +/ L:0 +/ L:0 e. L:0 tmp1) e. x)# tmp1 ) take_2pair=: 3 : 0 NB. u i.5 /:~ ( -. ; =/ L:0 tmp=. ~. , /:~ L:0 y cp y) # tmp ) take_3card=: 3 : 0 NB. take_3card i.5 combination 3/5 tmp0=:, ,./@{ y;y;y tmp1=: ~. /:~ L:0 tmp0 ((; +/ L:0 +/ L:0 e. L:0 tmp1) e. 3)# tmp1 )