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

It sounds like you want a list of all the permutations of the letters in a certain word. CPAN has plenty of modules to do just that, such as List::Permutor, Algorithm::Permute, and so on.

Once you gt the permutations, you check those against a list of valid words. How you get that is up to you, but it's bascially a hash (or database) lookup.

Update: I had the name for List::Permutor wrong. :(
--
brian d foy <brian@stonehenge.com>
Subscribe to The Perl Review
  • Comment on Re: scrambling all letters in a word until all combinations are found

Replies are listed 'Best First'.
Re^2: scrambling all letters in a word until all combinations are found (duplicates)
by tye (Sage) on Jan 23, 2006 at 19:29 UTC

    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        

      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"; }