Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Depth First Search and Boggle

by kelan (Deacon)
on Sep 26, 2004 at 19:51 UTC ( [id://394001]=note: print w/replies, xml ) Need Help??


in reply to Re: Depth First Search and Boggle
in thread Depth First Search and Boggle

Note to anyone testing this algorithm out, it works well except for a small bug.

Because the $seen matrix is being passed into sub-calls by reference, any changes to it will still be there when the recursive find_words call returns. That messes up further calls to find_words because the seen-matrix is lying, in a sense.

To fix it, just add this line as the last line of the find_words sub (outside of the two for-loops), so that the seen-matrix is properly reset for a given call's ancestors:

$seen->[ $x ][ $y ] = 0;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2024-04-24 23:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found