Re: Re: Increasing scattered subsequence
- To: mathgroup at smc.vnet.net
- Subject: [mg80113] Re: [mg80086] Re: Increasing scattered subsequence
- From: Fred Simons <f.h.simons at tue.nl>
- Date: Mon, 13 Aug 2007 04:26:32 -0400 (EDT)
- References: <fa11b990e477.46baf2d3@bgu.ac.il> <D370EB89-ACFD-4FFF-B4E7-84A25FF267C5@mimuw.edu.pl> <C82B7D4D-6C0B-47E1-8603-DEE030A6E387@mimuw.edu.pl> <f69ab100e04a.46bc3a23@bgu.ac.il> <28688943.1186820838583.JavaMail.root@m35> <op.twwnxqppqu6oor@monster.gateway.2wire.net> <200708121116.HAA27746@smc.vnet.net>
Here is another oneliner for this problem(?): In[4]:= lst = {9, 2, 10, 3, 14, 9}; In[5]:= n = -\[Infinity]; Reap[If[# > n, Sow[#]; n = #] & /@ lst][[2, 1]] Out[6]= {9, 10, 14} Fred Simons Eindhoven University of Technology Andrzej Kozlowski wrote: > (...) >>> Also, there is something about this question and the earlier you sent >>> me that make sme suspicious. What do you say "you need to use >>> recursion and pattern matching, Select and Join"? This sounds to me >>> like some sort of test problem so I have decided to answer it but >>> without using any of these functions (although it may not be the >>> simplest way to do this). So here is my answer: >>> >>> ls = {9, 2, 10, 3, 14, 9}; >>> >>> Reverse[Last[Last[Reap[NestWhile[With[{a = First[Ordering[#, -1]]}, >>> Sow[#[[a]]]; Take[#, a - 1]] &,ls,Length[#] > 0 &]]]]] >>> >>> {9, 10, 14} >>> >>>
- References:
- Re: Increasing scattered subsequence
- From: Andrzej Kozlowski <akoz@mimuw.edu.pl>
- Re: Increasing scattered subsequence