This is likely the wrong way to go about this. I don't need to iterate over all of the poker hands to know that there are 52!/47!/5! of them, that 52-4 have 4 aces, 4*48*47/2 have 3 aces, 13*4*12*6 are full houses, 13*4*48*47/2 have 3-of-kind in them so 13*4*48*47/2-13*4*12*6 are 3-of-kind hands, etc.

Those are the types of calculations that you need to make, rather than just counting (if you want to do this fast enough to be useful in real time).

I suppose you could try doing weighted combinations where instead of combinations of cards you do combinations of classes of cards. For example, if the only types of cards that will change the standings are an ace or a spade, then you'd do combinations of the following classes: non-spade aces, ace of spades, non-ace spades, non-ace non-spades. Those combinations then lead to calculations like I was doing above. I not sure that would be any simpler.

You could look at my Permuting with duplicates and no memory (now part of Algorithm::Loops) and compare it to a standard lexicographic permutations combinations algorithm to see how my changes deal with duplicates and try to make similar changes to one of the combinations algorithms. Likely, you could search and find an algorithm for doing combinations with duplicates somewhere.

- tye        


In reply to Re: Optimising combinatorial iterations by filtration (mu) by tye
in thread Optimising combinatorial iterations by filtration by Moron

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.