Re: split again

*To*: mathgroup at smc.vnet.net*Subject*: [mg73667] Re: split again*From*: "Ray Koopman" <koopman at sfu.ca>*Date*: Sat, 24 Feb 2007 02:16:04 -0500 (EST)*References*: <ermd8n$hmd$1@smc.vnet.net>

On Feb 23, 1:48 am, Arkadiusz.Ma... at gmail.com wrote: > Hi, > > Thank you very much for your help in my provious post. Now, consider > please a list > > z=Table[Random[],{1000}]; > > zSplit=Split[z,#1<=0.7 === #2>=0.7]; (bulit thanks to your > help) > > I want to pick the first sublist of zSplit that consists of elements > <= 0.7 and whose length is greater than a certain number (say 5). I > think that a good candidate would be using Cases and variations of _ , > but I don't know how. > > What I want to do (and what my both posts are about) is to find the > first sublist of z with all elements less than A and the length of > this sublist must be greater than B. Maybe there exists better > solution than to Split z in advance since what I need to do in my next > step is to find ONLY the FIRST sublist of splitted z. > > Thanks again, > > Arek SeedRandom[2]; z = Table[Random[],{20}] {0.238705,0.844529,0.473928,0.421515,0.512692, 0.0228035,0.529257,0.0507012,0.74907,0.632356, 0.0725195,0.251276,0.902785,0.672727,0.419794, 0.512577,0.404555,0.00984124,0.168643,0.50482} A = .7; B = 5; n = Flatten[Position[isplit = Split@UnitStep[z - A], _?(Length@# > B && First@# == 0&), {1}, 1]/.{}->{0}][[1]] 3 If no run exists with the desired properties then n will be 0. Otherwise, n is the position in isplit of the desired run, and Length@Flatten@Take[isplit,n-1] + {1, Length@isplit[[n]]} {3,8} gives the first & last positions of the run in z.