Re: Re: how to get the longest ordered sub sequence of a
- To: mathgroup at smc.vnet.net
- Subject: [mg103231] Re: [mg103177] Re: how to get the longest ordered sub sequence of a
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Fri, 11 Sep 2009 05:25:52 -0400 (EDT)
- References: <h87pgp$5gt$1@smc.vnet.net> <200909101117.HAA17704@smc.vnet.net>
- Reply-to: drmajorbob at yahoo.com
That's the longest CONSECUTIVE non-decreasing subsequence.
Bobby
On Thu, 10 Sep 2009 06:17:34 -0500, Emu <samuel.thomas.blake at gmail.com>
wrote:
> 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
>
--
DrMajorBob at yahoo.com
- References:
- Re: how to get the longest ordered sub sequence of a list in
- From: Emu <samuel.thomas.blake@gmail.com>
- Re: how to get the longest ordered sub sequence of a list in