Part 1
Given a string, composed of a-z and the underscore '_' character, and a reference to an array of dictionary words, return an array of words that matches the hangman pattern as defined by the string. Examples, assuming that the ref to the dictionary array is taken from something like /usr/words/dict:
@matches = f("____", \@dict); # @matches would be every 4 letter word + in @dict @matches = f("__rl", \@dict); # @matches could include 'earl', 'perl' +, 'curl', etc.
Part 2
Given the same string as above, the list of words that were matched, and a array of characters that have already been 'guessed' by the hangman player, return a character within a-z that is not in the array of guessed characters that appears the most in the possible word list. As an example:
While 'e' would be the letter that would match 3 out of these 7 words, it has already been guessed and cannot be selected. So out of the rest of the remaining letters, only 'i', 't' or 'w' would get 2 out of 7 words, so either could be returned (programmer's choice).$string = "s__s"; @letters_guessed = qw( s e ); @possible_words = qw( suns sets sees saws skis sews sits ); $guess = g( $string, \@possible_words, @letters_guessed );
Extra Credit for Part 1
Effectively add the list of guessed characters to this part such that the underscore characters can only be replaced by characters that are NOT on this list.
-----------------------------------------------------
Dr. Michael K. Neylon - mneylon-pm@masemware.com
||
"You've left the lens cap of your mind on again, Pinky" - The Brain
It's not what you know, but knowing how to find it if you don't know that's important
In reply to (Golf) Hangman Player by Masem
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |