I'm way behind on digesting what people have come up with, but I showed
this at last night's NYCJUG:
https://code.jsoftware.com/wiki/NYCJUG/2021-08-10#All_Selected_Hands_-_Solution_2
.
It's R. E. Boss's original solution wrapped in a loop to iterate
through the argument in pieces small enough to fit in memory.

Since then, I made two improvements: I use characters rather than integers
(since they are all less than 52) to speed up the manipulation of the large
intermediate results and I incorporated my table of the 5-card hands in
ascending order of hand strength in order to make the scoring better
reflect the strength of the possible hands.

ashpREB=: 3 : 0
   c4_4=. (,.|.)2 comb 4 [ c3_48=. 3 comb 48 [ c4_52=. a.{~4 comb 52
   'chsz iters'=. */ &> (3&{.;3&}.) q:#c4_52  NB. Chunk size, number
of iterations
   scores=. 0$~#c4_52
   for_ix. i.iters do. ixs=. (ix*chsz)+i.chsz
      sc0=. (2{."1 t),"1 "3 c3_48{"1"1 _ (t=.c4_4{"(_ 1) ixs{c4_52)-.~
"1 a.{~i.52
      scores=. (+/"1 y i. 1 0 2|:,/0 2 1 3|:sc0) ixs}scores
   end.
   scores
NB.EG allph=. ashpREB RH5c  NB. "RH5c" is 2598960x5 character matrix
of hands in ascending order.
)

The speed-up improved the run time from about 1300 seconds to about 800
seconds but my scoring change put it back up to 1200 seconds, which is a
hundred-fold improvement on my original version.

On Wed, Aug 11, 2021 at 4:39 PM 'Mike Day' via Programming <
[email protected]> wrote:

> NB. No history in this comment - side-effect of using iPad away from home
> WiFi
>
> My farthingsworth:
>
> Suppose you’ve got one canonical solution in the form of an array of
> m-hands compatible (in some way) with one canonical n-hand.  (Devon asked
> for all 5-hands given 1 (or 6 permutations of 1) 4-hand,  while Mr Boss has
> also looked at all 4-hands given a 5-hand.)
>
> If, say, we require all 5-hands given a 4-hand,  I suggest it’s sufficient
> to solve for
> 0 1 2 3.  All solutions for other 4-hands are equivalent after mapping.
>
> eg,  if we require the solution for h =. 3 5 8 13,  the to-vector is
>       to =. 3 5 8 13 0 1 2 4 6 7 9 10 11 12 14 .... 51,
> ie h, h-.~ i.52
>
> If the canonical solution for i.4 is S, the solution for 3 5 8 13 is
>      to { S .
>
> I assume the order of the 4-hand is partially significant,  in that the
> first pair prescribes required cards, and the second pair excluded cards.
> If desired,  we could
> set, or perhaps require:
>    h =. (/:~ 2{.h),  /:~ _2{.h   .
>
> The mapped solution, (to { S) , may,  if required,  be re-sorted within
> hands and between hands to exactly reproduce a solution generated by other
> mechanisms discussed in this thread.
>
> Apologies if this is so painfully obvious that it didn’t need stating.
> Even more if it’s wrong!
>
> Mike
>
> Sent from my iPad
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>


-- 

Devon McCormick, CFA

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

Reply via email to