Re: how to get the longest ordered sub sequence of a
- To: mathgroup at smc.vnet.net
- Subject: [mg103212] 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:24:15 -0400 (EDT)
- Reply-to: hanlonr at cox.net
lst = {1, 8, 2, 4, 3, 5}; Select[oss = Select[Subsets[lst], OrderedQ], Length[#] == Max[Length /@ oss] &] {{1, 2, 4, 5}, {1, 2, 3, 5}} Select[oss = Select[Subsets[lst], OrderedQ[Reverse[#]] &], Length[#] == Max[Length /@ oss] &] {{8, 4, 3}} Bob Hanlon ---- a boy <a.dozy.boy at gmail.com> wrote: ============= Thank all! your answers are right! However,what I need is the longest not-strict ordered items of a given list L, not a segment of L. For example, {1,8,2,4,3,5} -- ascending--> {1,2,4,5} {1,8,2,4,3,5} --descending-->{8,4,3} Because when I think this question ( http://groups.google.com/group/comp.soft-sys.math.mathematica/browse_thread/thread/f82401b1a517310c/9ca72a83a2313f50?lnk=gst&q=a.dozy.boy#9ca72a83a2313f50 ): For any integer k and 3^k, suppose 2^j is the closest to 3^k, Gap[k]=| 3^k-2^j| is the subtraction . Gap = Function[k, x = k*Log[2, 3]; Min[3^k - 2^Floor[x], 2^Ceiling[x] - 3^k]]; list=Table[{i, Gap[i]}, {i, 1, 5000}] I want to find a non-strict decreasing items of {Gap[i]} . On Wed, Sep 9, 2009 at 7:53 PM, Fred Simons <f.h.simons at tue.nl> wrote: > 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 > -- Bob Hanlon
- Follow-Ups:
- Re: Re: how to get the longest ordered sub
- From: Fred Simons <f.h.simons@tue.nl>
- Re: Re: how to get the longest ordered sub
- From: Leonid Shifrin <lshifr@gmail.com>
- Re: Re: how to get the longest ordered sub
- From: DrMajorBob <btreat1@austin.rr.com>
- Re: Re: how to get the longest ordered sub