in reply to "Jumble" solver
This is pretty nifty. I would suggest, though, that you allow for anagrams. Simple example, because I haven't had my coffee yet this morning and I don't have the brain power to thing of a longer anagram: evil, vile and live have the same letters. Yes, I guess the people who write the jumble probably make sure there's only one solution, but just in case you might want your lookup table to be a hash of arrays:
#option -u(nscramble) ... if($opt_u){ #open default if not specified open(IN, $opt_d ? "<$opt_d" : "<$database"); #build the lookup table while(<IN>){ ($value, $key) = split /:/; chomp $key; push @{$hash{$key}}, $value; # each hash value is an arrayref } #arange the letters to match format of database $sorted = join "",sort split//,$opt_u; #display unscrambled word print join ', ', @{$hash{$sorted}} , "\n"; }
|
|---|