P is for Practical | |
PerlMonks |
Re: How to get a ideal hashby ELISHEVA (Prior) |
on Apr 03, 2009 at 14:44 UTC ( [id://755288]=note: print w/replies, xml ) | Need Help?? |
In your post (OP) you specify that all numbers other than "-1" are "unique" - but what exactly do you mean? Do you mean that
The two statements are quite different. Unless you are absolutely certain a priori that (2) is true, your algorithm is going to need to check for multiple paths to each number. Then you will have to decide whether those multiple paths are an error or not. Assuming that multiple paths to each number are an error, your code will need to keep track of each path found to each number. I posted code below to illustrate the point, mainly as a contrast to BrowserUk's elegant solution. I do so with reservations. Bloodnok is right - it is considered bad form on Perl Monks to post a question without at least trying to show your own efforts. But BrowserUK is right too - the OP has posted a difficult problem. We aren't trying to be mean when we say do it yourself: it is just that we are donating our time so others can learn. Trying to solve the problem on your own is essential to really understanding the solution. For further discussion of the point, see The path to mastery.
Best, beth Update: added my agreement with BrowserUk's observation about difficulty below.
In Section
Seekers of Perl Wisdom
|
|