A stylistic issue. I'd recursively traverse the character to add words. Using eval there is an error-prone sledgehammer. What happens with words that include single quotes? You're trusting your input in a way that I avoid.
One minor note. Instead of a breadth-first search, my natural inclination would be a depth-first recursive search, and then I could do a local $seen{$pos} = 1; to mark a node seen. That's not better or worse than what you did, just different. But it does get rid of the queue management. Here is untested code to show you what that bit could look like (note that I am assuming the cleverness of putting the actual word in the word slot):
for my $pos (keys %map) { add_solutions($pos, $dict); } my %seen; sub add_solutions { my ($node, $tree) = @_; local $seen{$node} = 1; my $char = $board{$node}; $tree = $tree->{$char} or return; push @solutions, $tree->{word} if $tree->{word}; for my $new_node (grep not $seen{$_}, @{$map{$node}}) { add_solutions($new_node, $tree); } }
In reply to Re: Improve My FaceBook Scramble Solver
by tilly
in thread Improve My FaceBook Scramble Solver
by Limbic~Region
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |