[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[FWP] Words made from letters in a given phrase



FWPers---

Last week was Logos Spirit Week, with many (annoying) activities and a
couple of fun puzzles. The most entertaining puzzle for me was: "How many
words can you make using the letters in 'Robert David Pritchett' " I don't
care much for corporate pep rallies, but I sure do love using Perl to cheat
in events! I used a huge free wordlist
[http://www.thecorsair.com/words1.zip], and banged out a script. The
dictionary file is ASCII and has one "word" per line, all lowercase.

Two solutions are below, mine and a co-worker's. I'm sure you can do it
(shorter|faster|more efficiently)! Or, of course, more FUN (which could also
mean longer, slower, and less efficiently)?

BTW, both solutions find 4,286 matches using the aforementioned list of
306,293 words. In case you care, both my coworker and I were disqualified
for "cheating".





[-- SPOLIER! Are you sure you don't want to try it yourself first? --]






    WORD: while(<>)
    	{
    	chomp;
    	$t = q/robert david pritchett'/;
    	$t =~ s/$_// || next WORD for(split//);
    	print "$_\n";
    	}



And since (TMTOWTDI = more opportunities for fun), here's the coworker's
script ...

    $input = "robert david pritchett";
    
    for ($i = 0; $i < 26; $i++)
    {
        $char = chr($i + 97);
        @count = ($input =~ m/$char/g);
        $inputletters[$i] = @count;
    }
    
    while (<>)
    {
        chomp;
    
        $good = 1;
    
        for ($i = 0; $i < 26; $i++)
        {
            $char = chr($i + 97);
            @count = m/$char/g;
            if (@count > $inputletters[$i])
            {
                $good = 0;
                $i = 26;
            }
        }
    
        print "$_\n" if $good;
    }




________________________
Eli Evans
Text Preparation Manager
Libronix Corp.
mailto:eli@libronix.com
http://www.libronix.com
Ec 12:12; Jn 21:22



==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe