Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Find Length Of Longest Ascending/Descending Sequence

by masak (Scribe)
on May 10, 2011 at 19:59 UTC ( #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


Comment on Re: Find Length Of Longest Ascending/Descending Sequence
Download Code
1+0 reply Replies are listed 'Oldest 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
Node Status?
node history
Node Type: note [id://904022]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (20)
As of 2015-07-07 16:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (91 votes), past polls