From: Bob Hanlon on

data = RandomInteger[{0, 9}, 50]

{1,9,6,7,9,8,2,2,2,1,4,0,9,9,9,2,8,2,8,0,1,4,4,3,4,9,9,4,2,6,9,4,9,8,4,3,9,4,0,5,1,7,2,0,7,2,6,2,1,6}

Select[sdata = Split[data, #2 < #1 &],
Length[#] == Max[Length /@ sdata] &]

{{9, 8, 4, 3}}

Select[sdata = Split[data, #2 <= #1 &],
Length[#] == Max[Length /@ sdata] &]

{{9, 8, 2, 2, 2, 1}}

Select[sdata = Split[data, #2 > #1 &],
Length[#] == Max[Length /@ sdata] &]

{{6, 7, 9}, {0, 1, 4}, {3, 4, 9},
{2, 6, 9}}

Select[sdata = Split[data, #2 >= #1 &],
Length[#] == Max[Length /@ sdata] &]

{{0, 9, 9, 9}, {0, 1, 4, 4},
{3, 4, 9, 9}}


Bob Hanlon

---- a boy <a.dozy.boy(a)gmail.com> wrote:

=============
how to get a (strict or not-strict)decreasing sub sequence of a list?
----------------

increasing ?


From: Fred Simons on
a boy wrote:
> how to get a (strict or not-strict)decreasing sub sequence of a list?
> ----------------
>
> increasing ?
>
>
>
lst=RandomInteger[{1,100}, {5000}];

With[{sublists=Split[lst, #1<#2&]},
With[{m=Max[Length /@ sublists]},
Select[sublists, Length[#]==m&]]]

{{3,19,22,33,51,66,89,95}}

Fred Simons
Eindhoven University of Technology

From: DrMajorBob on
I've been assuming the OP wanted the LONGEST increasing subsequence.

But he never said that.

D'oh!

Bobby

On Thu, 10 Sep 2009 06:24:48 -0500, dh <dh(a)metrohm.com> wrote:

>
>
> Hi,
>
> we can do this with intermediate variables.
>
> E.g. assume the data is in d:
>
> d = RandomInteger[10, 12]
>
> then we get an non-strict increasing sub list by:
>
> t = d[[1]];
>
> Select[d, If[# >= t, t = #; True, False] &]
>
> the following gives a strict increasing sub list, without the first
>
> element, that we need to append later:
>
> t = d[[1]];
>
> Select[d, If[# > t, t = #; True, False] &]
>
> Daniel
>
>
>
> a boy wrote:
>
>> how to get a (strict or not-strict)decreasing sub sequence of a list?
>
>> ----------------
>
>>
>
>> increasing ?
>
>>
>
>
>


--
DrMajorBob(a)yahoo.com

From: DrMajorBob on
> I've been assuming the OP wanted the LONGEST increasing subsequence.
>
> But he never said that.

Oops, yes he did... in the subject line... and the code below doesn't do
it.

Bobby

On Thu, 10 Sep 2009 18:08:18 -0500, DrMajorBob <btreat1(a)austin.rr.com>
wrote:

> I've been assuming the OP wanted the LONGEST increasing subsequence.
>
> But he never said that.
>
> D'oh!
>
> Bobby
>
> On Thu, 10 Sep 2009 06:24:48 -0500, dh <dh(a)metrohm.com> wrote:
>
>>
>>
>> Hi,
>>
>> we can do this with intermediate variables.
>>
>> E.g. assume the data is in d:
>>
>> d = RandomInteger[10, 12]
>>
>> then we get an non-strict increasing sub list by:
>>
>> t = d[[1]];
>>
>> Select[d, If[# >= t, t = #; True, False] &]
>>
>> the following gives a strict increasing sub list, without the first
>>
>> element, that we need to append later:
>>
>> t = d[[1]];
>>
>> Select[d, If[# > t, t = #; True, False] &]
>>
>> Daniel
>>
>>
>>
>> a boy wrote:
>>
>>> how to get a (strict or not-strict)decreasing sub sequence of a list?
>>
>>> ----------------
>>
>>>
>>
>>> increasing ?
>>
>>>
>>
>>
>>
>
>


--
DrMajorBob(a)yahoo.com