teknokid1 has asked for the wisdom of the Perl Monks concerning the following question:

I have got an Perl array like: @array = (1,2,3,4,5,6,1,2,3,4,1,2,1,2,3,4,5,6,7,8,9...............) This numeric sequence will be always sequentially increasing, unless it encounters, The beginning of the new sequentially increasing numeric sequence. SO in this array we get sequentially increasing many subsists. There can be n numbers in this array and so can many sequentially increasing subsists.These sublists will always be increasingly sorted. I want to extract the BEGINING and the ENDING positions of these subsists in the array with respect to array beginning position 0. (1,2,3,4,5,6) BEG=0 END=5 (1,2,3,4) BEG=6 END=9 (1,2) BEG=10 END=11 (1,2,3,4,5,6,7,8,9) BEG=12 END=20 . . . . . . . .
  • Comment on Finding the BEGINNING and ENDING positions of sequentially increasing sublists from a perl numeric array

Replies are listed 'Best First'.
Re: Finding the BEGINNING and ENDING positions of sequentially increasing sublists from a perl numeric array
by moritz (Cardinal) on Nov 09, 2011 at 14:24 UTC

    What have you tried so far? Where are you having trouble?

    We'll be happy to help with algorithm problems and perl troubles, but we're not a code writing service, so please show your own efforts here (post code!)

    It's not so hard: loop over the array, and keep a variable around with the next value you expect. When that expectation isn't met, you know that a new subsequence starts.