Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^4: Find Length Of Longest Ascending/Descending Sequence

by wind (Priest)
on May 09, 2011 at 21:57 UTC ( #903844=note: print w/replies, xml ) Need Help??


in reply to Re^3: Find Length Of Longest Ascending/Descending Sequence
in thread Find Length Of Longest Ascending/Descending Sequence

The result is 1 more than the length of the longest capture.

Why? If the full string is "123", then the result should be 3. If it's "21234", then the result should be 4. Still need to take overlaps into account even if you just want the length.

Btw, still have the typo in your last bit of code where you use min instead of max.

my $longest = min map length,

Replies are listed 'Best First'.
Re^5: Find Length Of Longest Ascending/Descending Sequence
by ikegami (Pope) on May 09, 2011 at 23:05 UTC

    You don't seen to have read my code closely enough. Specifically, you missed that I capture one short of the whole sequence.

    Why? If the full string is "123", then the result should be 3.

    For "123", "12" is captured and length("12") + 1 is 3.

    If it's "21234", then the result should be 4.

    For "21234", "123" is captured and length("123") + 1 is 4.

    Still need to take overlaps into account even if you just want the length.

    True, but I avoided needing to capture the same digit twice, and thus I avoided the need to visit the string twice.

    you use min instead of max.

    Thanks, fixed.

      you missed that I capture one short of the whole sequence.

      You're right, I missed the fact that when using the lookahead assertion you didn't capture the last digit.

      Obviously that could be "fixed" if you added a '.' to the end, but that would introduce the overlapping problem.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://903844]
help
Chatterbox?
[marto]: afternoon all
[Corion]: Hi marto ;)
[Corion]: Eily: Yeah - my French isn't even good to understand jokes, much less to make them :-D
[Corion]: marto: That post is a repost/duplicate of Excel sheet data write issue :-D
[Corion]: Whoops - Merging worksheets in .xls in one Excel sheet
[marto]: Corion, whoops, can the moderation me amended?
[Corion]: marto: We could vote, unconsider and reconsider ;)
[Corion]: "vote keep", I meant ;)
[Corion]: marto: But that aside, I hope you are well!
Corion is slowly acclimatizing to working only four days a week

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2017-09-21 14:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (248 votes). Check out past polls.

    Notices?