On 7 Aug 99, at 9:17, Matthew Wickline wrote: > bernie@fantasyfarm.com wrote: > > boolean subroutine to determine whether a word matches > > a probe/jots result; _fast_ is more important than small. > So now the problem is reduced to finding the number of jotts > a probe should get for a given target word. I don't know > that this is the fastest way to do it, but this seems good > to me: > > sub get_jotts { > my($probe, $target) = @_; > my %letters; > for ( split('',$target) ) > { $letters{$_}++ }; > my $jotts = 0; > for ( split('',$probe) ) > {$jotts++ if $letters{$_}-- > 0}; > $jotts; > } I was musing a bit [after my previous response here] and I can come up with a slight improvement, I think. There's no need to generate that hash every time [since you'll be checking a LOT of words]. Not sure how to initialize it quickly [it'd be neat if there was some way to pre-calculate the whole mess and "load it" in a real-fast swoop], but if the master word list had a precomputed hash for each word stored as a list. Then in the subr, instead of the first loop it could just do: my %letters = @$wordletters ; It is easy enough to precalculate these lists and write them to a file, that I guess would look like: RADAR ('R', 3, 'D', 1, 'A', 2) STEEL ('E', 2, 'T', 1, 'S', 1, 'L', 1) [...etc.. for several thousand more...] Then the program initialization would suck up that whole mess somehow. This is a place I"d be inclined to use a hash: $wordlist{'word'} = ref to array of 'letters'. You'd 'delete' the words as you eliminated them from contention. [that'd make the inner loop of the checker be something like: foreach my $wd (keys %wordlist) { delete $wordlist{$wd} if &count_jots($wd, $probe) != $jots ; } then you'd make a guess by doing: my $probe = (keys %wordlist)[rand(keys %wordlist)] ; /Bernie\ -- Bernie Cosell Roanoke Electronic Village mailto:bernie@rev.net Roanoke, VA ==== Want to unsubscribe from Fun With Perl? Well, if you insist... ==== Send email to <fwp-request@technofile.org> with message _body_ ==== unsubscribe