http://www.perlmonks.org?node_id=122812

cecil36 has asked for the wisdom of the Perl Monks concerning the following question: (strings)

I want to write a script in perl that will allow a user to type in a string of letters and have the script return all the matches in a word list. My script should be able to find all possible letter arrangements for the letters typed in. In case you are wondering what the script is for, I'm planning on using the script as an aid in playing Scrabble.

Originally posted as a Categorized Question.

  • Comment on How would I be able to find all possible letter arrangements?

Replies are listed 'Best First'.
Re: How would I be able to find all possible letter arrangements?
by arhuman (Vicar) on Nov 02, 2001 at 19:46 UTC
    Directly from perlfaq4 :

    Here's a little program that generates all
    permutations of all the words on each line of
    input. The algorithm embodied in the permute()
    function should work on any list:
    #!/usr/bin/perl -n # tsc-permute: permute each word of input permute([split], []); sub permute { my @items = @{ $_[0] }; my @perms = @{ $_[1] }; unless (@items) { print "@perms\n"; } else { my(@newitems,@newperms,$i); foreach $i (0 .. $#items) { @newitems = @items; @newperms = @perms; unshift(@newperms, splice(@newitems, $i, 1)); permute([@newitems], [@newperms]); }
Re: How would I be able to find all possible letter arrangements?
by drinkd (Pilgrim) on Nov 03, 2001 at 09:08 UTC
    You will of course need to check the permuted list to figure out which words are in the Official Scrabble Players Dictionary.

    There is a search web page here that you can have your script search through a web connection using LWP::Useragent and HTTP::Request::Common.

    drinkd