MathGroup Archive 2012

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

Search the Archive

Re: Find a maxlist of within subsets

Hi all,

Given a list [a,b,c,d,e,f,g], I am trying to find the maxlist for overlapping subsets of 3 [{abc},{bcd},{cde},{def},{efg}].  To make things more difficult, this list needs to always retain the first and last member of the list [{a},{abc},{bcd},{cde},{def},{efg},{g}].  And, finally, I only want to know if the middle variable of each subset is equal to or greater than the other variables in the subset.

So, for the list [60,67,65,64,69,69,62], which would then be broken into the subsets [{60},{60,67,65},{67,65,64},{65,64,69},{64,69,69},{69,69,62},{62}] I want to return the value: [60, 67, 69, 69, 62].

Any thoughts on the code I could use?

Try this function:

mySplit[lst_List] := Module[{rule},
   rule[{x_, y_, z_}] := y;
      Select[Partition[lst, 3,
        1], #[[2]] >= #[[3]] && #[[2]] >= #[[1]] &]], First[lst]],

For your example,

lst = {60, 67, 65, 64, 69, 69, 62};

it gives

mySplit[{60, 67, 65, 64, 69, 69, 62}]

{60, 67, 69, 69, 62}

Which is not exactly what you obtained as an exampkle, but on the other hand it is what you described in words.

Have fun, Alexei

Alexei BOULBITCH, Dr., habil.
ZAE Weiergewan,
11, rue Edmond Reuter,
L-5326 Contern, LUXEMBOURG

Office phone :  +352-2454-2566
Office fax:       +352-2454-3566
mobile phone:  +49 151 52 40 66 44

e-mail: alexei.boulbitch at

  • Prev by Date: How to create links or bookmarks to jump to sections inside a notebook
  • Next by Date: Re: Find a maxlist of within subsets
  • Previous by thread: Re: Find a maxlist of within subsets
  • Next by thread: Re: Find a maxlist of within subsets