Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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

( #122812=categorized question: print w/ replies, xml ) Need Help??
Contributed by cecil36 on Nov 02, 2001 at 19:39 UTC
Q&A  > strings


Description:

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.

Answer: How would I be able to find all possible letter arrangements?
contributed by arhuman

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]); }
Answer: How would I be able to find all possible letter arrangements?
contributed by drinkd

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

Please (register and) log in if you wish to add an answer



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (4)
    As of 2014-10-21 01:44 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      For retirement, I am banking on:










      Results (95 votes), past polls