Output:use Modern::Perl; open my $DICT, '<', './2of12inf.txt' or die "Could not open dictionary +: $!"; my @dictionary; my %words8; my %results; while (<$DICT>) { chomp; next unless $_; chop if /%$/; next if length > 8; my $sorted = join '', sort split ''; push @dictionary, $sorted; $words8{$sorted}++ if length == 8; } my $maxword = 0; my $solution = ''; for my $word8 ( keys %words8 ) { my $regex = join '?', split '', $word8; for my $word (@dictionary) { $results{$word8}++ if $word =~ /($regex?)/ and $1 eq $word; } if ( $results{$word8} > $maxword ) { $maxword = $results{$word8}; $solution = $word8; say "$solution can make $maxword words"; } } say "Finished";
Corrected the "off-by-one" error.aabdellu can make 55 words abellrsu can make 118 words aeikprrs can make 131 words ahopstuw can make 136 words ... acehprst can make 288 words adeinrst can make 313 words adeoprst can make 316 words aeilprst can make 344 words aeinprst can make 346 words Finished
Re-corrected the off-by-one error which was due to an empty line in the small test dictionaries I used.
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
My blog: Imperial DeltronicsIn reply to Re: Challenge: 8 Letters, Most Words
by CountZero
in thread Challenge: 8 Letters, Most Words
by Limbic~Region
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |