in reply to Re: Find Length Of Longest Ascending/Descending Sequence
in thread Find Length Of Longest Ascending/Descending Sequence
Here's my round 1 solution. Fancier solutions to come, work willing.
while (<DATA>) { chomp; my $line = $_; my @chars = split ''; my $diff = join '', map {($chars[$_+1] - $chars[$_]) % 10} (0..$#c +hars-1); my $maxlen = 0; my $maxpos = 0; while ($diff =~ m/(1+|9+)/g) { if ($maxlen < length $1) { $maxlen = length $1; $maxpos = pos($diff) - $maxlen; } } printf "pos = % 2s, str = '%s'\n", $maxpos, substr($line, $maxpos, + $maxlen + 1); }
|
|---|