HangmanGolf


Cheating at hangman-type puzzles with Perl

You may need to replace the path to the dict wordfile to suit your system. This doesn't really do the smart things that you need for hangman or Wheel of Fortune (all letters revealed when guessed), but is perfect for "fill in the missing letters" puzzles.

#!/usr/bin/perl -wln

BEGIN {
   $e = lc shift;
   @ARGV = qw(/usr/share/dict/words);

   $d=$m=$e;$l=length $e;
   tr/\x5f/\0/ for $d,$m;
   tr/\x00/\xFF/c for $m;
}

chomp; $l == length or next;
( $m & lc ) eq $d and print;

Usage example:

$ perl hangman.pl "__C_N_I_E__T__Y"
inconsiderately
unconsiderately