in reply to Re: Depth First Search and Boggle
in thread Depth First Search and Boggle
Maybe I should have included this in my post. Right now I have a hash of a hash of hash... where each character maps to a key. ex.
hello equals $hash{h}{e}{l}{l}{o} = {}.
I planned on walking through this hash as I went through the dfs sub, but wanted to get the sub correct before I made it more complicated. Same thing with the singular call to dfs. I figured it would easier to examine the output if I started from one point. I could have wrapped the initial dfs call inside two for loops, but in the intrest of getting dfs working I decided to start from one point only.Update: Here is my preprocess code, if you have any suggestions.
my ($dict) = "/usr/share/dict/words"; open (FILE, $dict) or die ("Can't open $dict: $!\n"); while (<FILE>) { chomp; next if length() < 3; @char = split //, $_; $pointer = \%{$word_tree{$char[0]}}; for (1 .. $#char) { $pointer = \%{$$pointer{$char[$_]}}; } } close (FILE);
|
|---|