MathGroup Archive 2009

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

Search the Archive

Re: Re: how to get the longest ordered sub

  • To: mathgroup at smc.vnet.net
  • Subject: [mg103240] Re: [mg103212] Re: [mg103158] how to get the longest ordered sub
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Fri, 11 Sep 2009 05:27:31 -0400 (EDT)
  • References: <200909101124.HAA18266@smc.vnet.net>
  • Reply-to: drmajorbob at yahoo.com

That's elegant... but Subsets gets HUGE if lst gets only slightly large.

Bobby

On Thu, 10 Sep 2009 06:24:15 -0500, Bob Hanlon <hanlonr at cox.net> wrote:

>
> 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
>
>


-- 
DrMajorBob at yahoo.com


  • Prev by Date: Re: docs for Style, etc. (Antialiasing)
  • Next by Date: Re: docs for Style, etc. (Antialiasing)
  • Previous by thread: Re: how to get the longest ordered sub sequence of a
  • Next by thread: Re: Re: how to get the longest ordered sub