Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

There are 25 letter sets that will cover 4 words of your sample dictionary:

[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, $_

In reply to Re^3: Challenge: 8 Letters, Most Words (2of12int.txt in 20^H^H 10 secs; Pure Perl) by BrowserUk
in thread Challenge: 8 Letters, Most Words by Limbic~Region

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (6)
    As of 2015-07-30 10:58 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (271 votes), past polls