MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: how to get the longest ordered sub sequence of a

  • To: mathgroup at smc.vnet.net
  • Subject: [mg103205] Re: [mg103158] how to get the longest ordered sub sequence of a
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Thu, 10 Sep 2009 07:22:54 -0400 (EDT)
  • Reply-to: hanlonr at cox.net

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 at gmail.com> wrote: 

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



  • Prev by Date: java heap space error
  • Next by Date: Re: Problem with recent file list in Mathematica 7
  • Previous by thread: Re: java heap space error
  • Next by thread: Solving a system of equations