in reply to permute n elements2

Store the results in a hash. The values don't matter, just use the unique property of hash keys to your advantage.
my %results; @results{permute(\@possibilities)} = 1;

Replies are listed 'Best First'.
RE: Re: permute n elements2
by Anonymous Monk on Oct 25, 2000 at 02:25 UTC
    thanks for info. just need to know where to insert into the program so it will eliminate repeating permutations. I did a permutation that should of yielded 420 rearrangements, I ended up with 11 of the same for each original ( close to 5000 permutations ). I await the expertise of the all knowing one!
      That depends on what program you're using.

      If you're using the snippet from the perlfaq, you'll have to modify it somewhat. The easiest solution would be to return the values instead of printing it. In that case, my solution works as stands.

      The FAQ answer is recursive, so modifying it to use a hash internally is non-trivial, and it would take more time to change and to debug. Hope this helps.

      A reply falls below the community's threshold of quality. You may see it by logging in.
(tye)Re: permute n elements2
by tye (Sage) on Oct 26, 2000 at 00:55 UTC
      I ran your program as printed. the following : a a b b b c d should have yielded 420 permutations. i get 4976 the same number as how...permut n..". The text you wrote says "To use it, first sort.... I'm a perl newbie,please give me layman details to make this program work w/o duplicate permutations and I will be eternally grateful to you!!!! email address swanhits@hotmail.com should you choose to be more direct. thanks waiting on your reply!!!

        I get 420. It appears you ran the wrong program. You use the program just like you showed (the sorting is included in the "Sample use" part of the code).

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