Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Re: finding longest common substring (ALL common substrings)

by welchavw (Pilgrim)
on Nov 20, 2003 at 20:43 UTC ( #308697=note: print w/ replies, xml ) Need Help??


in reply to Re: finding longest common substring (ALL common substrings)
in thread finding longest common substring

Hmmm...I tried your code and I am confused by at least the outputs for some inputs. Maybe you have an explanation for the following result? (I must confess, I really tried the code out since I have never used ^N before, so I apologize if I'm missing something here).

sub lcs{ our %subs = (); my $n = @_; shift =~ m[^.*(.+)(?{ $subs{ $^N }++ })(?!)] while @_; my @subs = sort{ length $b <=> length $a } grep{ $subs{ $_ } == $n } keys %subs; return wantarray ? @subs : $subs[ 0 ]; } $" = ", "; my @inputs = ( ["ABCDEF", "BCD", "QXDAF"], #okay result ["AAAA", "AA"] #spurious result(???) ); for (@inputs) { @subs = lcs @$_; print "@$_=>@subs\n"; } __END__ __OUTPUT___ ABCDEF, BCD, QXDAF=>D AAAA, AA=>AAA

,welchavw


Comment on Re: Re: finding longest common substring (ALL common substrings)
Download Code
Re: Re: Re: finding longest common substring (ALL common substrings)
by BrowserUk (Pope) on Nov 20, 2003 at 22:31 UTC

Log In?
Username:
Password:

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

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

    For retirement, I am banking on:










    Results (223 votes), past polls