Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^4: Challenge: 8 Letters, Most Words (top 50)

by Limbic~Region (Chancellor)
on Oct 05, 2013 at 02:43 UTC ( #1056988=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Challenge: 8 Letters, Most Words (top 50)
in thread Challenge: 8 Letters, Most Words

BrowserUk,
Hopefully my code won't take longer than 24 hours to run (against the 2of12inf.txt). I too find these results odd. If I haven't any logic bugs or fence post errors, my code will put any doubt to rest though I suspect you will figure it out before my code finishes ;-)

Update: My code only took 12 minutes and it disagrees with your results. I manually checked and I think you must have a bug somewhere. Your winning solution (aeilprst: 552) really only gets 344. I even included duplicates (if there were any) to try and account for the delta but came up empty handed. See below:

#!/usr/bin/perl use strict; use warnings; my %winner = map {$_ => undef} qw/a e i l p r s t/; open(my $fh, '<', '2of12inf.txt') or die "Unable to open '2of12inf.txt +' for reading: $!\n"; WORD: while (<$fh>) { chomp; $_ = lc($_); tr/a-z//cd; next if ! $_ || length($_) > 8; my %word; ++$word{$_} for split //; for my $l (keys %word) { next WORD if ! exists $winner{$l} || $word{$l} > 1; } print "$_\n"; } __END__ ail ails air airs aisle ale alert alerts ales alit alp alps alter alters ape apes apse apt apter are ares arise art arts as asp aspire aster astir at ate ear earl earls ears east eat eats era eras erst esprit eta etas ilea irate ire ires is isle islet it its la lair lairs lap laps lapse las laser last late later lea leap leaps leapt leas least lei leis lept lepta lest let lets liar liars lie lies lip lips lira liras lire lisp lisper list lit lite liter liters litre litres pa pail pails pair pairs pal pale paler pales palest pals par pare pares pars parse part parties parts pas past paste pastel pastier pat pate pates pats pea peal peals pear pearl pearls pears peas peat peats pelt pelts per peril perils pert pest pet petal petals pets pi piaster piastre pie pier piers pies pilaster pile piles pirate pirates pis pit pita pitas pits plait plaits plaster plat plate plates platies plats plea pleas pleat pleats pliers plies praise prate prates pries priest prise psi rail rails raise rap rape rapes rapist raps rapt rasp rat rate rates rats re real realist reap reaps relit rep repast reps res rest retail retails rial rials rile riles rip ripe ripest rips rise rite rites sail sale salt salter saltier sap sari sat sate satire sea seal sear seat sepal sepia septa sera serial set silt sip sir sire sit sitar site slap slat slate slept slier slip slit spa spar spare spat spate spear spelt spiel spilt spiral spire spirea spit spite splat split sprat sprite stair stale staler staple stapler star stare steal step stile stir strap strep stria striae strip stripe tail tails tale tales tali tap tape taper tapers tapes tapir tapirs taps tar tare tares tarp tarps tars tarsi tea teal teals tear tears teas ti tie tier tiers ties tile tiler tilers tiles tip tips tire tires tis trail trails traipse trap traps trial trials tries trip tripe tripes triple triples trips tsar

Cheers - L~R


Comment on Re^4: Challenge: 8 Letters, Most Words (top 50)
Download Code
Re^5: Challenge: 8 Letters, Most Words (top 50)
by BrowserUk (Pope) on Oct 05, 2013 at 10:51 UTC
    Your winning solution (aeilprst: 552) really only gets 344.

    Indeed. I had de-dup code that didn't.

    Once properly de-duped, I get aeilprst: 344:

    ail ails air airs aisle ale alert alerts ales alit alp alps alter alte +rs ape apes apse apt apter are ares arise art arts as asp aspire aster astir at ate ear earl earls ears east eat eats era eras e +rst esprit eta etas ilea irate ire ires is isle islet it its la lair lairs lap laps lapse las laser last late later lea leap le +aps leapt leas least lei leis lept lepta lest let lets liar liars lie lies lip lips lira liras lire lisp lisper list lit lite lite +r liters litre litres pa pail pails pair pairs pal pale paler pales palest pals par pare pares pars parse part parties parts pas pas +t paste pastel pastier pat pate pates pats pea peal peals pear pearl pearls pears peas peat peats pelt pelts per peril perils pert pe +st pet petal petals pets pi piaster piastre pie pier piers pies pilaster pile piles pirate pirates pis pit pita pitas pits plait plait +s plaster plat plate plates platies plats plea pleas pleat pleats pliers plies praise prate prates pries priest prise psi rail rails rai +se rap rape rapes rapist raps rapt rasp rat rate rates rats re real realist reap reaps relit rep repast reps res rest retail retails +rial rials rile riles rip ripe ripest rips rise rite rites sail sale salt salter saltier sap sari sat sate satire sea seal sear seat s +epal sepia septa sera serial set silt sip sir sire sit sitar site slap slat slate slept slier slip slit spa spar spare spat spate spear +spelt spiel spilt spiral spire spirea spit spite splat split sprat sprite stair stale staler staple stapler star stare steal step stile s +tir strap strep stria striae strip stripe tail tails tale tales tali tap tape taper tapers tapes tapir tapirs taps tar tare tares tarp + tarps tars tarsi tea teal teals tear tears teas ti tie tier tiers ties tile tiler tilers tiles tip tips tire tires tis trail trails trai +pse trap traps trial trials tries trip tripe tripes triple triples trips tsar

    But now that is in second place to aeinprst: 346

    air airs an ani anise ant ante antes anti antis ants antsier ape apes +apse apt apter are ares arise arisen art arts as asp aspen aspire aster astern astir at ate ear earn earns ears east eat eats en +ens entrap entraps era eras erst esprit eta etas in inapt inept inert ins insert inset instep inter inters irate ire ires is it its na +e nap nape napes naps nastier neap neaps near nears neat nest net nets nip nips nit nite niter niters nites nitre nitres nits pa pai +n pains paint painter painters paints pair pairs pan pane panes panier paniers pans pant pantie panties pantries pants par pare parent + parents pares pars parse part parties parts pas past paste pastern pastier pat pate pates pats pea pear pears peas peat peats pen + penis pens pent per pert pertain pertains pest pet pets pi piaster piastre pie pier piers pies pin pine pines pins pint pints pir +ate pirates pis pit pita pitas pits praise prate prates pries priest print prints prise psi rain rains raise ran rani ranis rant ran +ts rap rape rapes rapine rapines rapist raps rapt rasp rat rate rates rats re reap reaps rein reins rent rents rep repaint repaints re +past reps res resin rest retain retains retina retinas retsina rinse rip ripe ripen ripens ripest rips rise risen rite rites saint sa +ne saner sap sapient sari sat sate satin satire sea sear seat sent sepia septa sera set sin sine sip sir sire siren sit sitar site s +nap snare snip snipe sniper snit spa span spar spare spat spate spear spent spin spine spinet spire spirea spit spite sprain sprat spr +int sprite stain stair star stare stein step stern sterna stir strain strap strep stria striae strip stripe tan tans tap tape taper t +apers tapes tapir tapirs taps tar tare tares tarn tarns tarp tarps tars tarsi tea tear tears teas ten tens tern terns ti tie tier t +iers ties tin tine tines tins tip tips tire tires tis train trains traipse trap traps tries trip tripe tripes trips tsar

    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.
      BrowserUk,
      Indeed. I had de-dup code that didn't.

      Is your code posted somewhere as I can't tell if this has been updated.

      Cheers - L~R

        I can't tell if this has been updated.

        No. This is completely different code to my first attempt. I thought I had posted it, but it seems that I didn't.

        This is the code in its final form:

        #! perl -slw use strict; use List::Util qw[ reduce ]; use Data::Dump qw[ pp ]; sub canBeMadeFrom { my( $sigRef, $word ) = @_; for( split '', $word ) { return unless exists $sigRef->{ $_ }; delete $sigRef->{ $_ }; } return 1; } my %stats; while( <> ) { chomp; next if length() > 8; my $sig = join '', sort split '', $_; push @{ $stats{ $sig } }, $_; } print STDERR scalar keys %stats; my @eights = grep length() == 8, keys %stats; my %eights; @eights{ @eights } = delete @stats{ @eights }; print my $i = @eights; for my $eight ( keys %eights ) { printf STDERR "\r%5d '%s'\t", $i--, $eight; my %sig; undef @sig{ split '', $eight }; for my $lesser ( keys %stats ) { next unless canBeMadeFrom( { %sig }, $lesser ); for my $word ( @{ $stats{ $lesser } } ) { push @{ $eights{ $eight } }, $word if canBeMadeFrom( { %si +g }, $word ); } } } my @ordered = sort{ @{ $eights{ $b } } <=> @{ $eights{ $a } } } keys %eights; for( 0 .. $#ordered ) { print "$ordered[ $_ ]: ", scalar @{ $eights{ $ordered[ $_ ] } }; print "@{ $eights{ $ordered[ $_ ] } }"; }

        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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (12)
As of 2014-10-31 13:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (217 votes), past polls