[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: longuest interleaved sequences
From: |
Jaroslav Hajek |
Subject: |
Re: longuest interleaved sequences |
Date: |
Fri, 21 May 2010 14:53:44 +0200 |
On Thu, May 20, 2010 at 10:19 PM, Judd Storrs <address@hidden> wrote:
> On Thu, May 20, 2010 at 3:39 PM, Jaroslav Hajek <address@hidden> wrote:
>> what about
>>
>> x = sort(rand(50,1)) ;
>> y = sort(rand(54,1)) ;
>>
>> [~, ix] = unique (lookup (y, x));
>> x = x(ix);
>> [~, iy] = unique (lookup (x, y));
>> y = y(iy);
>>
>> and remove one element from the longer sequence if needed.
>
> I think this generates an interleaved subset of x and y that is
> longest. It tosses values out, though. I was trying to find the
> longest continuous subsequence. Your code finds the longest (possibly
> non-continuous) subsequence which may be what Pascal was wanting.
Well, subsequence != contiguous subsequence. At least I think
contiguity was not specified.
>I always forget about lookup() ;)
>
That's not that bad, you may be aware of the other funcs (histc and
ismember) that use lookup behind the scene. But they generally do some
extra work, while lookup is a "raw" binary search.
--
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz