Given two lists, such as
@a = qw(fred bob joe jim mary elaine);
@b = qw(frank joe jim mary bob);
What's the best way to find the largest subset of @b in @a? Here I mean the largest ordered subset: (joe, jim, mary) would be correct, but (bob, joe, jim, mary) would not.
The best (read "easiest") solution I could come up with is to join(',', @a) and then join(',', @b[$start..$end]), and then use the index function to see if (and where) the join from @b occurs in the join from @a. There must be some perl magic to do this in a more clean, faster way.
And yes, I know that what I'm asking is of quite high computational complexity. Thanks for any suggestions!
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|