6
2
A program should take an input on stdin, and guess what a word might be. It should run as a session. One example session is shown below. Characters are fed to it, with a * for a letter not revealed; it should remember letters already revealed. It shows possible words in a list if the total number words found is less than 20, otherwise it shows the count of words.
I recommend /usr/share/dict/words
on any Linux/Unix for the list of words, or your favourite word list on other platforms.
Example session (yours may vary):
>>> *****
6697 matches
>>> G****
312 matches
>>> *u***
Trying Gu***
35 matches
>>> Gu**s
Gus's
Guy's
guess
gulfs
gulls
gulps
gum's
gun's
gurus
gusts
gut's
guy's
12 matches
>>> **e**
Trying Gue*s
Is it "guess"?
I did this some years ago in JavaScript, except that it was not golfed and was a real Hangman player following the usual rules, including guessing only one letter at a time.
– PleaseStand – 2011-02-07T01:38:17.007To remove bias due to path lengths, can we assume that the word list is in a file named 'w' in the working directory? – Peter Taylor – 2011-02-07T13:11:36.160
@peter That would be fine, but make it clear. – Thomas O – 2011-02-07T13:31:56.197