http://qs321.pair.com?node_id=102144

perl_wizard2 has asked for the wisdom of the Perl Monks concerning the following question:

You know those puzzles where you answer 5 questions, then take certain letters out of the answers to re-arrange thos letters into a new word?

Once you know the letters that are needed for the last word, is there a good perl program to show you all the combinations of dictionary words that are possible?

I did the code below, but I've got to wonder, is there a better way?

cat linux.words | perl -e 'while(<>) {if(/^[rgtnaie][rgtnaie][rgtnaie] +[rgtnaie][rgtnaie][rgtnaie][rgtnaie][rgtnaie][rgtnaie]$/) { %letters += (); chomp; $word = $_; while($letter = chop) {$letters{$letter}++;} + if(($letters{'e'} == 2) && ($letters{'t'} == 2) && ($letters{'i'} == + 1) && ($letters{'n'} == 1) && ($letters{'g'} == 1) && ($letters{'r'} + == 1) && ($letters{'a'} == 1)) {print "FOUND: $word\n"; }}}'

The code above would find all words that have 2 e's, 2 t's, and one each of i, n, g, r and a. The one I found was 'integrate'.

TIA,

Jason

Edit Masem 2001-08-06 - Title appended with "for finding anagrams"