It won't win "most compact", but it might prove more efficient than many:

#! perl -slw use strict; sub z { my $soFar = 1; my $lastC = substr $_[0], 0, 1; my( $lastP, $bestN, $bestP ) = ( 0 ) x 3; for my $p ( 1 .. length( $_[0] )-1 ) { my $this = substr $_[0], $p, 1; my $d = abs( $this - $lastC ); if( $d != 1 and $d != 9 ) { $soFar = 1; $lastP = $p; } ++$soFar; if( $soFar > $bestN ) { $bestN = $soFar, $bestP = $lastP; } $lastC = $this; } return $bestN, $bestP; } while( <DATA> ) { chomp; print; my( $l, $p ) = z( $_ ); print ' ' x $p, substr( $_, $p, $l ), "\t", $l, "\n"; } __DATA__ 01234567890123456789 78901234567890123456 98765432109876543210 21098765432109876543 01234567890987654321 012345678890123456789 789012345677890123456 987654321099876543210 210987654322109876543 012345678900987654321 012345678909876543210

In the absence of an answer re: 090, I've noted your abs(1) criteria. Also, first of equal longest.

Could be simplified if you don't need to know where the longest occurs.

Output:

C:\test>junk 01234567890123456789 01234567890123456789 20 78901234567890123456 78901234567890123456 20 98765432109876543210 98765432109876543210 20 21098765432109876543 21098765432109876543 20 01234567890987654321 01234567890987654321 20 012345678890123456789 890123456789 13 789012345677890123456 78901234567 11 987654321099876543210 98765432109 11 210987654322109876543 21098765432 11 012345678900987654321 01234567890 11 012345678909876543210 012345678909876543210 21

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".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re: Find Length Of Longest Ascending/Descending Sequence by BrowserUk
in thread Find Length Of Longest Ascending/Descending Sequence by Limbic~Region

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.