in reply to Re: Adjacent numbers
in thread Adjacent numbers

Not included in the sample data, but in the description:

if ($previous_num + 1 == $num || $previous_num - 1 == $num) {
Dum Spiro Spero

Replies are listed 'Best First'.
Re^3: Adjacent numbers
by BrowserUk (Patriarch) on Nov 19, 2015 at 22:09 UTC

    It'll take a little more than that.

    It will need to remember the direction in which the numbers are running, otherwise 1,2,1,2,3,2,3,4,3... will be seen as a run.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice.
      otherwise 1,2,1,2,3,2,3,4,3... will be seen as a run.
      well, they are adjacent, after all. The OP would have to specify, whether e.g 2,3,1 should be treated as group, or not.
      In other words, whether a preceding sort step could distort the desired outcome.
        The OP would have to specify, whether e.g 2,3,1 should be treated as group, or not.

        From the OPs sample data, I think his intent is clear; but your interpretation is a possibility I suppose.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
        In the absence of evidence, opinion is indistinguishable from prejudice.