Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Find Length Of Longest Ascending/Descending Sequence

by masak (Scribe)
on May 10, 2011 at 19:59 UTC ( [id://904022]=note: print w/replies, xml ) Need Help??


in reply to Find Length Of Longest Ascending/Descending Sequence

My Perl 6 contribution:
my $seq = "82665409266027476709324472"; my $diff = join "", map { ($^b - $^a) % 10 }, ($seq.comb Z $seq.comb.rotate); my $longest = $diff.comb(/9+ | 1+/, :match).max({.to - .from}); say $seq.substr($longest.from, $longest.to - $longest.from + 1); # 654

Replies are listed 'Best First'.
Re^2: Find Length Of Longest Ascending/Descending Sequence
by ambrus (Abbot) on May 19, 2011 at 09:44 UTC

    Would this work for strings like "834567"? I think you may need to replace ($seq.comb Z $seq.comb.rotate) with something like ($seq.comb[0..*-2] Z $seq.comb[1..*-1]).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://904022]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-03-28 23:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found