in reply to Re: scrambling all letters in a word until all combinations are found
in thread scrambling all letters in a word until all combinations are found

Words often contain repeated letters so you'd be better off using Algorithm::Loops since it's permutation routines handle duplicate items unlike Algorithm::Permute or List::Permutor (I see no List::Permute on CPAN), as far as I could see.

- tye        

  • Comment on Re^2: scrambling all letters in a word until all combinations are found (duplicates)

Replies are listed 'Best First'.
Re^3: scrambling all letters in a word until all combinations are found (duplicates)
by brian_d_foy (Abbot) on Jan 23, 2006 at 19:41 UTC

    I'm not sure what you mean by duplicate items. List::Permutor uses each element of the list and doesn't discard duplicates, which is probably what the original poster wants. If that's not the case and he wants only unique letters, a quick filter discards duplicates before he gets started.

    --
    brian d foy <brian@stonehenge.com>
    Subscribe to The Perl Review

      The duplicates tye mentions reside in the result set of a permutation effectivly operating on the (unique) index set of an array, rather than the (maybe) non-unique array members.

      For an array qw(n o o n) List::Permutor will list all the 4! == 24 "solutions", of which only 6 are unique:

      use strict; use warnings; use Algorithm::Loops qw(NextPermute); use List::Permutor; local $\ = $/; my @x = sort qw(n o o n); # sort required, c/f A::L docs print "Algoritm::Loops::NextPermute says"; do {print "@x"} while NextPermute @x; my $perm = new List::Permutor qw/n o o n/; print "List::Permutor says"; while (my @x = $perm->next) { print "@x"; }