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

Re: Solving Anagrams

by jdporter (Paladin)
on Jan 24, 2005 at 18:29 UTC ( [id://424656]=note: print w/replies, xml ) Need Help??


in reply to Solving Anagrams

First thing you do is delete from your %dictionary all ur-words that contain any letters not present in your source phrase. Another preprocess you can do is eliminate all ur-words that are already too long.
my $source_phrase = 'perl wisdom'; my $source_urword = join '', grep /\w/, sort_uniq( split //, $source_p +hrase ); # or whatever for ( keys %dictionary ) { delete $dictionary{$_} if /[^$source_urword]/ || length($_) > length($source_urword); }
That should significantly enhance the performance of any subsequent algorithm... unless you're unlucky enough to have a source phrase containing nearly all the available alphabet.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-26 07:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found