MathGroup Archive 2007

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

Search the Archive

Re: question in mathematica

  • To: mathgroup at smc.vnet.net
  • Subject: [mg80099] Re: question in mathematica
  • From: Ray Koopman <koopman at sfu.ca>
  • Date: Sun, 12 Aug 2007 07:23:17 -0400 (EDT)
  • References: <fa11b990e477.46baf2d3@bgu.ac.il>

On Aug 10, 11:43 pm, Andrzej Kozlowski <a... at mimuw.edu.pl> wrote:
> On 10 Aug 2007, at 10:12, Ivan Egorov wrote:
>> 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}.
>> You need to use recursion, pattern matching, Select and Join.

None of those are needed, unless you call NestList recursive.

Pick[lis, Last/@FoldList[{Max[#1[[1]],#2], #1[[1]] < #2}&,
                         {lis[[1]], True}, Rest@lis] ]
(not tested)



  • Prev by Date: RandomComplex documentation
  • Next by Date: [Mathematica 6] "formatting notebook contents" messages, why so many in Mathematica 6?
  • Previous by thread: Re: question in mathematica
  • Next by thread: Re: question in mathematica