I have a string that represents a number as such:
445123966682
In that number there are 3 digits that are in ascending order: 123
I want to write a rule that checks any numerical string I give it to see if there are 3 or more numbers in ascending or descending order.
True: 445123 or 445987
False: 192837 or 97531
I presume the best way is to use a RegEx check, but I am not the best at RegEx. The only other option I can think of is to either iterate the characters and check or cast the number to an integer and use modulo + division to grab each digit off of the number and compare with the next number in the series.
Edit
Sorry, I meant contiguous order. 123 is valid, 135 is not.
With regexp, it’s kind of trivial:
It’s dumb, but the problem is simple enough that the dumb solution is the best one.