Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

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

by cecil36 (Pilgrim)
on Nov 02, 2001 at 19:39 UTC ( #122812=categorized question: print w/replies, xml ) Need Help??
Contributed by cecil36 on Nov 02, 2001 at 19:39 UTC
Q&A  > 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.

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.


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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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?

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

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (3)
    As of 2021-03-01 02:00 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found