You make a good point, and I made the following change to the my program:
# Find how close each letter is to half of the total word possibilitie
+s to ensure maximum gain every guess after being sorted
foreach my $occur (keys %alphabet) {
$alphabet{$occur} = abs($#narrowed/2 - abs($alphabet{$occur} - $#n
+arrowed + 1));
}
say $_ foreach @narrowed; # Word list
say $#narrowed + 1;
say sort { $alphabet{$a} <=> $alphabet{$b} } keys %alphabet; # Sort as
+cendingly; whichever letter is closest to 0, i.e., and therefore whic
+hever letter will eliminate the most words.
However, as I play, I notice that although it does eliminate a lot of words very quickly, when it gets to a low amount of words, it becomes useless, telling me to guess letters that are not in any of the words, and telling me to guess letters that are in all of the words last.
Surely, when it comes to this point, the user can easily guess on his own but that is not really the point. I want the program to be able to find the individual word in a small amount of guesses. Perhaps I should use your method when there are more than, say, 10 possibilities, and mine from there on out.
Example illustrating my point:
$ perl hangman.pl "_ _ _ _ _ _ _ _" ""
_ _ _ _ _ _ _ _
0
10588
rantislodecgupmhbyfkwvxzqj
$ perl hangman.pl "_ _ _ _ _ _ _ _" "r"
_ _ _ _ _ _ _ _
r
5252
atlnsieodcgumhpbyfkwvxzqjr
$ perl hangman.pl "_ _ _ _ _ _ _ _" "ra"
_ _ _ _ _ _ _ _
r|a
2761
tolnsdgueichpmbfykwvxzqjra
$ perl hangman.pl "_ _ _ _ _ t _ _" "ra"
_ _ _ _ _ t _ _
r|a
165
isncdolupmghbfykvxejqwtraz
$ perl hangman.pl "_ _ _ _ _ t i _" "ra"
_ _ _ _ _ t i _
r|a
bulletin
cosmetic
despotic
dietetic
domestic
eclectic
ecliptic
egoistic
elliptic
esthetic
eutectic
holistic
hypnotic
logistic
phonetic
quixotic
theistic
17
slhpodungmxytieqbwrajkfvcz
$ perl hangman.pl "_ _ _ _ _ t i _" "ras"
_ _ _ _ _ t i _
r|a|s
bulletin
dietetic
eclectic
ecliptic
elliptic
eutectic
hypnotic
phonetic
quixotic
9
unohlpxdytiqbwrajkgfvmscze
$ perl hangman.pl "_ _ _ _ _ t i _" "rasu"
_ _ _ _ _ t i _
r|a|s|u
dietetic
eclectic
ecliptic
elliptic
hypnotic
phonetic
6
dyhtincowraxjukgfevmslqbzp
$ perl hangman.pl "_ _ _ _ _ t i _" "rasud"
_ _ _ _ _ t i _
r|a|s|u|d
eclectic
ecliptic
elliptic
hypnotic
phonetic
5
yticwraxdjukhgfenvmspqbzol
$ perl hangman.pl "_ _ _ _ _ t i _" "rasudy"
_ _ _ _ _ t i _
r|a|s|u|d|y
eclectic
ecliptic
elliptic
phonetic
4
wraxdjyukhgftienvmslcpqbzo
$ perl hangman.pl "_ _ _ _ _ t i _" "rasudyw"
_ _ _ _ _ t i _
r|a|s|u|d|y|w
eclectic
ecliptic
elliptic
phonetic
4
wraxdjyukhgftienvmslcpqbzo
I am kind of speaking to myself here, so this node is just publishing my own mental thoughts. Feel free to comment or object them.
I don't mind occasionally having to reinvent a wheel; I don't even mind using someone's reinvented wheel occasionally. But it helps a lot if it is symmetric, contains no fewer than ten sides, and has the axle centered. I do tire of trapezoidal wheels with offset axles. --Joseph Newcomer
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.