Three clicks could have taken you to Permuting with duplicates and no memory. Now it will only require one. (:

The link of mine that you originally linked to does what I usually think of as "counting" in a strange base (no, it isn't "combinations" in my book -- I'm curious what, if any, the official mathematical term for it is) and so would iterate through N**N cases, giving you many more than the N! cases you wanted.

Since you don't need to avoid duplicates, you can probably do it more simply. The documentation for Algorithm::Permute has links to some good examples.

...Looking at Permuting with duplicates and no memory to see if there were any obvious improvements to be had if you assume no duplicates, I realized that I can change sort to reverse which should make it rather faster (while still handling duplicates). I'd compare it to Algorithm::Permute but that is all written in XS which makes it: 1) unfair, and 2) too hard to get running at the moment. Maybe later. (:

Update: I compared the updated version of my code against the code that Algorithm::Permute includes in its sample benchmark code. My code beat all but the XS versions in speed (about 1/2 as fast as the XS version) and beat all of them in that my code handles duplicate items in the list while none of the others did. :)

        - tye (but my friends call me "Tye")

In reply to (tye)Re: Iterating through permutations by tye
in thread Iterating through permutations by dragonchild

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.