2
$\begingroup$

I am still a beginner and maybe I want to do something too complicate!

After 29 cycles I obtained the following events list: L={0,0,1,0,1,1,1,1,1,2,2,1,1,2,3,2,1,1,2,2,2,3,3,3,2,2,2,3,4}. The first time the events 1,2,3 and 4 manifest, are at the 3rd,10th,15th and 29th cycle, respectively. I would like to cut the cycle series:

CL={{0,0,1},{0,1,1,1,1,1,2},{2,1,1,2,3},{2,1,1,2,2,2,3,3,3,2,2,2,3,4}}

and automate the first event search to obtain the following list:

EL={3,10,15,29}

I am so far only able to get the first elements by using:

cyclefinder=TakeWhile[L, # < 1 &]
eventfinder=FirstPosition[L, x_ /; x = 1]

I have already searched in previous answers (pe. Finding the first position in a list that is over a certain value), but maybe you can help me to find the right one, because in my serie the value is incremental. Thank you! LXXX

$\endgroup$
  • 1
    $\begingroup$ You can obtain EL with Table[FirstPosition[L, k], {k, 4}] // Flatten. $\endgroup$ – J. M.'s ennui Feb 22 '16 at 13:09
  • $\begingroup$ To expand on J.M.'s answer, here is how you can get CL once you have computed EL: Map[Take[L, #]& ,Rest[FoldList[{#1[[2]] + 1, #2}&, {0, 0}, Sort[Union[EL, {Length[L]}]]]] ] There may be a more efficient way to do this, but it is the first thing that came to mind. $\endgroup$ – C. Woods Feb 22 '16 at 15:56
  • 1
    $\begingroup$ Hallo J.M. and C.Woods! Thank you for your answers! Your commands work very well! My task for today is to tray to make a function out of them, because theoretically the cycles I can get are infinite! I will tell you if I make it! $\endgroup$ – Three Shell Feb 23 '16 at 9:33
  • $\begingroup$ Ok! I got the first: eventfinder[r_] := Table[FirstPosition[#, n], {n, 1, r, 1}] & /@ {L} // Flatten $\endgroup$ – Three Shell Feb 23 '16 at 10:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.