Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^4: Words in Words

by sarchasm (Acolyte)
on Sep 30, 2011 at 22:03 UTC ( #928939=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Words in Words
in thread Words in Words

This process only needs to identify 1 word in the list that meets the criteria resulting in a unique list of the words that were contained within other words.

I suppose there would still be a problem if this process doesn't look at the words that preceed each word because something could be missed.

I have this code working and it sure is fast at producing a list of words. It just needs to return 1 word instead of all of the words that match and ensure that it searches the entire list.

Thank you!


Comment on Re^4: Words in Words
Re^5: Words in Words
by BrowserUk (Pope) on Sep 30, 2011 at 22:17 UTC
    This process only needs to identify 1 word in the list that meets the criteria resulting in a unique list of the words that were contained within other words.

    Then add a single line to my solution above and it should reduce the time taken by roughly a factor of 10. Ie. A projected 1 hour:

    #! perl -slw use strict; my @words = do{ local @ARGV = 'words.txt'; <> }; chomp @words; my $all = join ' ', @words; my $start = time; my $n = 0; for my $i ( @words ) { for my $j ( $all =~ m[ ([^ ]*$i[^ ]*) ]g ) { next if $j eq $i or $j eq "${i}s" or $j eq "${i}'s"; print "$j contains $i"; last; ## Added } } printf STDERR "Took %d seconds for %d words\n", time() - $start, scalar @words;

    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://928939]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (11)
As of 2014-09-17 11:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (72 votes), past polls