Re: how to get the longest ordered sub sequence of a list in
- To: mathgroup at smc.vnet.net
 - Subject: [mg103177] Re: how to get the longest ordered sub sequence of a list in
 - From: Emu <samuel.thomas.blake at gmail.com>
 - Date: Thu, 10 Sep 2009 07:17:34 -0400 (EDT)
 - References: <h87pgp$5gt$1@smc.vnet.net>
 
On Sep 9, 6:37 pm, a boy <a.dozy.... at gmail.com> wrote:
> how to get a (strict or not-strict)decreasing sub sequence of a list?
>                                     =
         ----------------
>
> increasing                               =
    ?
Try using Split.
In[185]:= lst=RandomInteger[{1,5},20]
Out[185]= {4,3,4,2,4,1,3,5,3,2,3,4,3,4,2,5,5,5,5,5}
In[186]:= Split[lst, #1 >= #2 &]
Out[186]= {{4, 3}, {4, 2}, {4, 1}, {3}, {5, 3, 2}, {3}, {4, 3}, {4,
2}, {5, 5, 5, 5, 5}}
Then you can find the longest non-strictly decreasing sub sequence as
follows.
In[187]:= m = Max[Length /@ %];
Select[%%, Length[#] == m &]
Out[188]= {{5, 5, 5, 5, 5}}
Sam
- Follow-Ups:
- Re: Re: how to get the longest ordered sub sequence of a
- From: DrMajorBob <btreat1@austin.rr.com>
 
 
 - Re: Re: how to get the longest ordered sub sequence of a