Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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

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
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 scrutinizing the Monastery: (6)
As of 2016-10-01 21:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?






    Results (8 votes). Check out past polls.