in reply to Challenge: 8 Letters, Most Words
Update2: Second guessing myself. Update: Amongst other possible errors, this rejects words that have more than 8 letters; whereas it should only reject words with more than 8 unique letters!
I get:
C:\test>1056884 words.txt a e i n o r s t: 458
Just brute force (takes 3 or 4 seconds on my 179000 word dictionary):
#! perl -slw use strict; my %stats; while( <> ) { chomp; next if length > 8; my $word = $_; push @{ $stats{ $_ } }, $word for split '', $word; } my @freq = sort{ @{ $stats{ $b } } <=> @{ $stats{ $a } }; } keys %stats; my %letters; ++$letters{ $_ } for @freq[ 0 .. 7 ]; my %uniq; for my $l ( keys %letters ) { WORD: for my $word ( @{ $stats{ $l } } ) { my %letters = %letters; for my $c ( split '', $word ) { unless( exists $letters{ $c } and --$letters{ $c } >= 0 ) + { #print( "rejected: $word" ); delete $uniq{ $word }; next WORD ; } } ++$uniq{ $word } ; } } print "@{[ sort keys %letters ]}: ", scalar keys %uniq;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Challenge: 8 Letters, Most Words (Update2:Then again :)
by Limbic~Region (Chancellor) on Oct 04, 2013 at 19:18 UTC | |
|
Re^2: Challenge: 8 Letters, Most Words (Update2:Then again :)
by McA (Priest) on Oct 04, 2013 at 19:47 UTC | |
by BrowserUk (Patriarch) on Oct 04, 2013 at 20:00 UTC | |
by Limbic~Region (Chancellor) on Oct 05, 2013 at 04:01 UTC | |
by McA (Priest) on Oct 04, 2013 at 20:20 UTC |