Re: Increasing scattered subsequence
- To: mathgroup at smc.vnet.net
- Subject: [mg80116] Re: Increasing scattered subsequence
- From: "Dana DeLouis" <dana.del at gmail.com>
- Date: Mon, 13 Aug 2007 04:28:05 -0400 (EDT)
>>> Write a function maxima[lis_List] which, given a list of numbers, >>> produces a list of those numbers greater than all those >>> that precede them. For example >>> >>> maxima[{ 9, 2, 10, 3, 14, 9}] returns { 9, 10, 14}. I'm missing some of the thread, but here's my attempt: Maxima[v_?VectorQ] := UnsortedUnion[FoldList[Max[#1, #2] & , First[v], Rest[v]]] UnsortedUnion[x_] := Reap[Sow[1, x], _, #1 & ][[2]] Maxima[{9, 2, 10, 3, 14, 9}] {9, 10, 14} Timing[Maxima[RandomPermutation[50]]] {0., {12, 22, 39, 40, 46, 49, 50}} -- HTH :>) Dana DeLouis Mathematica 6.0 Having to use Mathematica 5.2 Help files Studying Mathematica 4.0 Book