in reply to Word Unscrambler
Returns:use strict; use warnings; my $letters = 'jboiac'; my ($lcount, $blanks, %lhash, $handle, @matches); $lcount = length($letters); $blanks = $letters =~ s/([^a-z])//g; $lhash{$_}++ for split //, $letters; open ($handle, 'dict1.dat'); while (<$handle>) { chomp; push @matches, $_ if scrabble($_); } close ($handle); print join "\n", sort { length($b) <=> length($a) || $a cmp $b } @matc +hes; sub scrabble { return 0 if length($_[0]) > $lcount; my ($nf, %wlhash); $wlhash{$_}++ for split //, $_[0]; for (keys %wlhash) { no warnings; return 0 if $lhash{$_} < $wlhash{$_} && ($nf += $wlhash{$_} - $lhash{$_}) > $blanks; } return 1; }
(abc wouldn't be allowed in Scrabble, but the Neopets game has some odd words in it, including names of Neopets. I had to add these manually as I went along using a second script)jacobi ciao abc bio boa cab cob jab jib job
|
|---|