So, it's this easy and fast to generate all possible poker hands:
   $5 comb3 52
2598960 5
   6!:2 '5 comb3 52'
0.18593328


On 1/18/08, R.E. Boss <[EMAIL PROTECTED]> wrote:
>
> In http://www.jsoftware.com/pipermail/programming/2007-August/007819.htmlI
> presented a more efficient verb than 'comb'
> http://www.jsoftware.com/help/dictionary/cfor.htm to determine all
> combinations. In Hui's essay
> http://www.jsoftware.com/jwiki/Essays/Combinations it was used to describe
> comb1 (without mentioning the origin).
>
> Scott pointed me to
> http://www.jsoftware.com/pipermail/programming/2007-February/005123.html ,
> which led me to another idea on combinations, called 'comb3'.
>
>    rnk 5 ts&>'10 comb 20';'10 comb1 20';'10 comb3 20'
> 2 1.27 1.20
> 1 1.03 1.24
> 0 1.00 1.00
>
> So comb3 is 3% faster and 24% leaner than comb1.
>
>    (10 comb1 20) -: 10 comb3 20
> 1
>
>   comb3=: [:; [:(,.&.><@;\.)/ >:@[EMAIL PROTECTED]
>
> (Perhaps a candidate for a Jem
> http://www.jsoftware.com/jwiki/DanBron#works_intended )
>
>
> With a slight modification (of the starting items), comb3 can be used to
> generate combinations with non-unique elements:
>
>   comb3a=: [:; [:(,.&.><@;\.)/ (($,:)i.)
>
>    2 comb3a 3
> 0 0
> 0 1
> 0 2
> 1 1
> 1 2
> 2 2
>
> Notice that x=0 gives a domain error in both cases, but this can easily be
> repaired (by ([EMAIL PROTECTED]:)`comb3 @.([EMAIL PROTECTED]) ).
>
>
> R.E. Boss
>
>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>



-- 
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to