Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
The stupid question is the question not asked
 
PerlMonks  

Re: Challenge: 8 Letters, Most Words

by Tux (Monsignor)
on Oct 05, 2013 at 08:51 UTC ( #1057015=note: print w/ replies, xml ) Need Help??


in reply to Challenge: 8 Letters, Most Words

I get 670 with aeilnrst using /usr/share/dict/words and 346 with aeinprst using 2of12inf, but I'd like to expand on this. All presented solutions take as a base that the letters should be able to create at least one 8-letter word. If I however assume that a 7-letter word with a random extra letter is able to create more words with shorter words, the number of possibilities explodes.

With the requirement of an 8-letter word: Reading ... length 8: 37514 length 7: 31449 length 6: 22043 length 5: 12337 length 4: 5826 length 3: 1892 length 2: 398 length 1: 26 Extending 7 ... Preparing ... Prepared 33552 Sorting ... 670 aeilnrst entrails 666 aeilprst pilaster 661 adeinrst detrains 651 adeilrst dilaters 651 aeinprst pantries 634 adeilnor irondale 631 aeinorst arsonite 626 aeginrst angriest 623 aeilmrst lamister 619 aeimnrst merantis 618 adeilnrs islander 615 aeloprst petrosal 614 adeiprst rapidest 607 aenoprst operants 605 aelnorst lonestar 598 adegilnr dearling 597 acenorst ancestor 595 aceinrst canister 594 abeilrst abristle 593 aeilorst realitos 670 aeilnrst 8 entrails 7 aliners alister anestri anilest antlers antsier elastin entrail lati +ner latrine 6 airest aliner altern alters aniler antler antres ariels arisen arist +e arline 5 aesir airns airts aisle aisne alert alien aline alist alsen alter an +ile anise 4 ains aire airn airt aits alit alts anes anil ansi ante anti ares are +t aril aris 3 ail ain air ait ale ali alt ane ani ans are art asl ate ats ean ear +eat ela eli 2 ae ai al an ar at ea el en er et ia ie il in ir it la le li ln lr lt + na ne ni 1 a e i l n r s
With the requirement of at least a 7-letter word: Reading ... length 8: 37514 length 7: 31449 length 6: 22043 length 5: 12337 length 4: 5826 length 3: 1892 length 2: 398 length 1: 26 Extending 7 ... Preparing ... Prepared 704575 Sorting ... 670 aeilnrst entrails 666 aeilprst pilaster 661 adeinrst detrains 651 aeinprst pantries 651 adeilrst dilaters 634 adeilnor irondale 631 aeinorst arsonite 626 aeginrst angriest 623 aeilmrst lamister 619 aeimnrst merantis 618 adeilnrs islander 615 aeloprst petrosal 614 adeiprst rapidest 607 aenoprst operants 605 aelnorst lonestar Use of uninitialized value in printf at test.pl line 57, <$fh> line 30 +5089. 604 adeilnst 598 adegilnr dearling 597 acenorst ancestor Use of uninitialized value in printf at test.pl line 57, <$fh> line 30 +5089. 597 adeilnrt 595 aceinrst canister 670 aeilnrst 8 entrails 7 aliners alister anestri anilest antlers antsier elastin entrail lati +ner 6 airest aliner altern alters aniler antler antres ariels arisen arist +e arline 5 aesir airns airts aisle aisne alert alien aline alist alsen alter an +ile anise 4 ains aire airn airt aits alit alts anes anil ansi ante anti ares are +t aril 3 ail ain air ait ale ali alt ane ani ans are art asl ate ats ean ear +eat ela 2 ae ai al an ar at ea el en er et ia ie il in ir it la le li ln lr lt + na ne ni 1 a e i l n r s
With 2of12ing and 8-letter word required: Reading ... length 8: 12687 length 7: 11571 length 6: 8303 length 5: 5122 length 4: 2546 length 3: 642 length 2: 62 Preparing ... Prepared 11926 Sorting ... 346 aeinprst painters 344 aeilprst pilaster 332 adeiprst rapidest 328 aeimprst primates 319 adeilrst lardiest 316 adeoprst adopters 314 aeilnpst panelist 313 adeinrst randiest 313 aeloprst polestar 312 aeilnrst entrails 310 adeimrst readmits 307 aeimnrst minarets 304 aceiprst practise 299 aelmprst tramples 297 acelprst spectral 296 aeginrst angriest 295 acenorst ancestor 293 aelprsty psaltery 291 adeilmst medalist 289 adeilprs lipreads 346 aeinprst 8 painters pantries pertains 7 antsier entraps nastier painter paniers panties parents parties past +ern 6 arisen aspire astern entrap esprit insert instep inters niters nitre +s paints 5 anise antes antis apter arise aspen aster astir earns inapt inept in +ert inset 4 airs ante anti ants apes apse ares arts earn ears east eats eras ers +t etas 3 air ani ant ape apt are art asp ate ear eat ens era eta ins ire its +nae nap 2 an as at en in is it pa pi re

And here is my code:

#!/usr/bin/perl use 5.16.2; use warnings; say "Reading ..."; my %magic; my %stats; open my $fh, "<", "/usr/share/dict/words"; while (<$fh>) { lc =~ m/^([a-z]{1,8})$/ or next; my $key = pack "(A)*", sort unpack "(A)*", $1; my $l = length $key; $magic{$key}{len} //= $l; $magic{$key}{cnt}++; push @{$magic{$key}{words}}, $1; $stats{$l}++; } say " length $_: $stats{$_}" for sort { $b <=> $a } keys %stats; say "Extending 7 ..."; foreach my $w7 (grep { $magic{$_}{len} == 7 } keys %magic) { #$magic{$w7.$_} //= { len => 8, cnt => 0, words => [] } for "a" .. + "z"; } say "Preparing ..."; my %x8; foreach my $key (keys %magic) { my $l = length $key; if ($l == 8) { $magic{$key}{ext}[$_] = [] for 1 .. 7; my $x8 = join "" => map "$_?" => unpack "(A)*" => $key; $x8{$key} = qr{^$x8$}; next; } push @{$stats{key}[$l]}, $key; } my @k8 = keys %x8; my $n8 = @k8; say "Prepared $n8"; foreach my $k8 (@k8) { --$n8 % 10 == 0 and print STDERR " $n8 \r"; my $x8 = $x8{$k8}; foreach my $l (reverse 1 .. 7) { foreach my $key (grep m/$x8/ => @{$stats{key}[$l]}) { push @{$magic{$k8}{ext}[$l]}, $key; $magic{$k8}{cnt} += $magic{$key}{cnt}; } } } say "Sorting ..."; my @top = sort { $magic{$b}{cnt} <=> $magic{$a}{cnt} } keys %magic; for (@top[0..19]) { printf "%6d %-8s %s\n", $magic{$_}{cnt}, $_, $magic{$_}{words}[0]; } my $best = $top[0]; say $magic{$best}{cnt}, " ", $best; sub showfirst { my ($l, $w) = @_; $w = substr $w, 0, 80 or return; $w =~ s/ \w+$//; say "$l $w"; } # showfirst showfirst ($magic{$best}{len}, join " " => sort @{$magic{$best}{words} +}); foreach my $l (reverse 1 .. 7) { my @w = map { @{$magic{$_}{words}} } @{$magic{$best}{ext}[$l]}; showfirst ($l, join " " => sort @w); }

Enjoy, Have FUN! H.Merijn


Comment on Re: Challenge: 8 Letters, Most Words
Select or Download Code
Re^2: Challenge: 8 Letters, Most Words
by tobyink (Abbot) on Oct 05, 2013 at 20:33 UTC

    "All presented solutions take as a base that the letters should be able to create at least one 8-letter word."

    Mine doesn't.

    use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1057015]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (11)
As of 2014-04-16 21:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (434 votes), past polls