in reply to Challenge: 8 Letters, Most Words
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 Deltronics
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Challenge: 8 Letters, Most Words
by McA (Priest) on Oct 04, 2013 at 20:34 UTC | |
by CountZero (Bishop) on Oct 04, 2013 at 20:52 UTC | |
by choroba (Cardinal) on Oct 04, 2013 at 21:57 UTC | |
by Limbic~Region (Chancellor) on Oct 05, 2013 at 03:42 UTC | |
by choroba (Cardinal) on Oct 05, 2013 at 07:27 UTC | |
| |
by Limbic~Region (Chancellor) on Oct 04, 2013 at 21:11 UTC | |
by CountZero (Bishop) on Oct 05, 2013 at 08:27 UTC | |
by LanX (Saint) on Oct 05, 2013 at 13:19 UTC | |
| |
by Limbic~Region (Chancellor) on Oct 05, 2013 at 12:57 UTC | |
| |
by McA (Priest) on Oct 04, 2013 at 21:06 UTC | |
by BrowserUk (Patriarch) on Oct 04, 2013 at 22:14 UTC | |
by McA (Priest) on Oct 04, 2013 at 23:58 UTC | |
| |
|
Re^2: Challenge: 8 Letters, Most Words
by Limbic~Region (Chancellor) on Oct 05, 2013 at 03:16 UTC | |
by CountZero (Bishop) on Oct 05, 2013 at 14:08 UTC |