Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
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
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 having an uproarious good time at the Monastery: (16)
As of 2014-09-18 17:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (120 votes), past polls