`[19:35:10.42] C:\test>1056884-calc hdb.dict
2aaaaenot
3aaaenotw
4aeinnotw
373.12408208847
[4] einnootw : one two nine ten
[4] efinnotv : five one nine ten
[4] einnotvw : one two nine ten
[4] eenostvw : one two seven ten
[4] einnotuw : one two nine ten
[4] einnostw : one two nine ten
[4] eghinnot : one eight nine ten
[4] ceinnotw : one two nine ten
[4] eehnortw : three one two ten
[4] efinnotw : one two nine ten
[4] efinotvw : five one two ten
[4] eiinnotw : one two nine ten
[4] eeinnotw : one two nine ten
[4] eghinotw : one two eight ten
[4] ehinnotw : one two nine ten
[4] einnortw : one two nine ten
[4] einnotwx : one two nine ten
[4] einostwx : six one two ten
[4] einnnotw : one two nine ten
[4] eginnotw : one two nine ten
[4] efnortuw : one two four ten
[4] einnotww : one two nine ten
[4] aeinnotw : one two nine ten
[4] einnottw : one two nine ten
[4] einnostx : six one nine ten
[3] eenostwx : one two ten
...
`
375 seconds isn't as impressive, but better than 24 hours :)
This makes use of another optimisation that only benefits when the dictionary is small like yours: `#! perl -slw
use strict;
use Time::HiRes qw[ time ];
$|++;
sub uniq{ my %x; @x{@_} = (); keys %x }
my $start = time;
my @lookup = map{
my $bits = pack 'C', $_;
[ grep vec( $bits, $_, 1 ), 0 .. 7 ]
} 0 .. 255;
my %dict;
my %alphabet;
while( <> ) {
chomp;
next if length > 8;
my $r = \%dict;
undef( $alphabet{ $_ } ), $r = $r->{ $_ } //= {} for sort split ''
+, $_;
push @{ $r->{_} }, $_;
}
my @alphabet = sort keys %alphabet;
my $best = [ 0, '' ];
my %stats;
sub X {
my( $first, $soFar, $tree ) = @_;
if( @$soFar == 8 ) {
my @words = uniq map {
my $r = \%dict;
$r = $r->{ $_ } for @{ $soFar }[ @{ $lookup[ $_ ] } ];
exists $r->{_} ? @{ $r->{_} } : ();
} 0 .. 255;
return unless @words > 1;
print @{ $best = [ scalar @words, join '', @$soFar ] } if @wor
+ds > $best->[0];
$stats{ join '', @$soFar } = \@words;
return;
}
for( grep $_ ge $first, @alphabet ) {
# next unless exists $tree->{ $_ };
X( $_, [ @$soFar, $_ ], $tree->{ $_ } );
}
return;
}
X( 'a', [], \%dict );
print time - $start; <STDIN>;
printf "[%d] %s : @{[ @{$stats{ $_ }} ]}\n", scalar @{$stats{$_}}, $_
+for
sort{ @{ $stats{ $b } } <=> @{ $stats{ $a } } } keys %stats;
`
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
@$soFar, $_ |
Comment onRe^2: Challenge: 8 Letters, Most Words (2of12int.txt in 20^H^H 10 secs; Pure Perl)SelectorDownloadCode