There's already a Golf out there that allows the player to play hangman; here, we'll reverse it and look at a two-parter golf that could be used to develop a Hangman player.

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:

$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 );
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).

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.