in reply to Re: Find Length Of Longest Ascending/Descending Sequence
in thread Find Length Of Longest Ascending/Descending Sequence
As far as I can tell, when using a purely regex solution, you pretty much have to keep the scanning for ascending and descending sequences separated. Otherwise overlapping sequences will be missed:
123xxxx56543
Capturing in one go will return qw(123 56 543) instead of qw(123 56 6543);
my $asc = join '|', map {"$_(?=".(($_+1)%10).")"} (0..9); my $dsc = join '|', map {"$_(?=".(($_+9)%10).")"} (0..9); while (<DATA>) { my $longest = max map length, /((?:$asc)+)/g, /((?:$dsc)+)/g; print "$longest\n"; }
Update: This was in reference to your last solution, as previous ones did take this into account.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Find Length Of Longest Ascending/Descending Sequence
by ikegami (Patriarch) on May 09, 2011 at 20:49 UTC | |
by wind (Priest) on May 09, 2011 at 21:57 UTC | |
by ikegami (Patriarch) on May 09, 2011 at 23:05 UTC | |
by wind (Priest) on May 09, 2011 at 23:33 UTC |