in reply to Re^4: Find Length Of Longest Ascending/Descending Sequence
in thread Find Length Of Longest Ascending/Descending Sequence

You don't seen to have read my code closely enough. Specifically, you missed that I capture one short of the whole sequence.

Why? If the full string is "123", then the result should be 3.

For "123", "12" is captured and length("12") + 1 is 3.

If it's "21234", then the result should be 4.

For "21234", "123" is captured and length("123") + 1 is 4.

Still need to take overlaps into account even if you just want the length.

True, but I avoided needing to capture the same digit twice, and thus I avoided the need to visit the string twice.

you use min instead of max.

Thanks, fixed.

  • Comment on Re^5: Find Length Of Longest Ascending/Descending Sequence

Replies are listed 'Best First'.
Re^6: Find Length Of Longest Ascending/Descending Sequence
by wind (Priest) on May 09, 2011 at 23:33 UTC
    you missed that I capture one short of the whole sequence.

    You're right, I missed the fact that when using the lookahead assertion you didn't capture the last digit.

    Obviously that could be "fixed" if you added a '.' to the end, but that would introduce the overlapping problem.