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

Re^11: Challenge: 8 Letters, Most Words

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


in reply to Re^10: Challenge: 8 Letters, Most Words
in thread Challenge: 8 Letters, Most Words

McA,
My brain is mush so unfortunately, this critique is just the things that jumped out at me.

%alphabet = (%alphabet, map { $_ => 1 } @chars);
Would be better written as:
@alphabet{@chars} = (); # No need to set values to 1 as you only ever +use keys
I am not sure why you avoid autovivication but
if(defined $sorted{$characters}) { push @{$sorted{$characters}}, $line; } else { $sorted{$characters} = [$line]; }
Would work just as well as:
push @{$sorted{$characters}}, $line;
You waste a lot of time going through loops that you abort early
foreach (my $pos2 = 0; $pos2 < $count; $pos2++) { next if $pos2 < $pos1;
Would work a lot more efficiently as:
for (my $pos2 = $pos1; $pos2 < $count; $pos2++) {
I haven't tested it but the way you determine if one is a subset of the other would probably be better as subtracting one hash from another.

Cheers - L~R


Comment on Re^11: Challenge: 8 Letters, Most Words
Select or Download Code
Re^12: Challenge: 8 Letters, Most Words
by McA (Deacon) on Oct 05, 2013 at 13:38 UTC

    Hi L~R,

    you're right with all. It is the result of putting code together when it's too late. I let the program run with Devel::NYTProf on a small subset of the dict. The result is what I assumed: Answering the question if a combination of letters is able to produce a word is the most expensive task. I tried to make it faster with a C-like implementation in perl, but it was slower than the hash-approach.

    The program is still running. Currently at iteration 879000. So, a long time to go... ;-)

    Anyway, a very very intersting puzzle. And it was fun looking at the different approaches and seeing that some of the "old" monks took that challenge.

    Best regards
    McA

      Re^12: Challenge: 8 Letters, Most Words

      ^12 just seems wrong somehow :)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2014-07-10 08:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (202 votes), past polls