Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^3: Longest Increasing Subset

by pryrt (Abbot)
on Oct 20, 2016 at 18:35 UTC ( [id://1174397]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Longest Increasing Subset
in thread Longest Increasing Subset

gilthoniel, you should be able to figure out how to use tybalt89's code as a starting point, but stopping as soon as you have a match. If you test the length of @answers at the end of the while loop, you can stop right away.

Or you could add a similar check to GrandFather's answer — though, not having run his, I'm not positive his will run in longest-first order.

Or, if the one to four lines of code (depending on how Perl-ly you think) that would be required to exit out of the loop when there's at least one element in @answers — if that's too difficult, you could look at my answer, which already tells you the one character you need to edit in order to get it to stop at the first match rather than listing them all. Given that my answer starts with the longest possible combination, and works its way down (inspired by your own structure, btw, to try to make it as easy for you to understand as possible), the first match will be the longest (or the first of the group that are all the same longest length, if there are multiple answers of the same length). If that won't work for you, please describe what feature of the answer does not meet your requirements.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-03-29 04:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found