MathGroup Archive 2009

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

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg103181] Re: how to get the longest ordered sub sequence of a list in
  • From: Valeri Astanoff <astanoff at gmail.com>
  • Date: Thu, 10 Sep 2009 07:18:19 -0400 (EDT)
  • References: <h87pgp$5gt$1@smc.vnet.net>

On 9 sep, 10:37, a boy <a.dozy.... at gmail.com> wrote:
> how to get a (strict or not-strict)decreasing sub sequence of a list?
>                                     =
         ----------------
>
> increasing                               =
    ?

Good day,

Just an example of what you can do :

In[1]:= list = {3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 7, 9, 8, 9};

In[2]:= sp = Split[list, OrderedQ[{#1, #2}] &]
Out[2]= {{3}, {1, 4}, {1, 5, 9}, {2, 6}, {5}, {3, 5, 7, 9}, {8, 9}}

In[3]:= pos = Ordering[sp, 1, (Length[#1] >= Length[#2]) &] // First
Out[3]= 6

In[4]:= sp[[pos]]
Out[4]= {3, 5, 7, 9}

hth

--
Valeri Astanoff


  • Prev by Date: Re: Re: confused about asserting variable is element of
  • Next by Date: Re: confused about asserting variable is element of Reals
  • Previous by thread: Re: Re: how to get the longest ordered sub sequence of a
  • Next by thread: Re: Re: how to get the longest ordered sub sequence of a