<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2657.73">
<TITLE>FW: Perl Quiz-of-the-Week #17</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=2>From: mjd@plover.com [<A HREF="mailto:mjd@plover.com">mailto:mjd@plover.com</A>] On Behalf Of Marco Baringer</FONT>
<BR><FONT SIZE=2>Sent: Wednesday, May 26, 2004 6:48 AM</FONT>
<BR><FONT SIZE=2>To: perl-qotw@plover.com</FONT>
<BR><FONT SIZE=2>Subject: Perl Quiz-of-the-Week #17 [x-adr]</FONT>
</P>
<BR>

<P><FONT SIZE=2>IMPORTANT: Please do not post solutions, hints, or other spoilers</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; until at least 60 hours after the date of this message.</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thanks.</FONT>
</P>

<P><FONT SIZE=2>IMPORTANTE: Por favor, no enviéis soluciones, pistas, o cualquier otra</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cosa que pueda echar a perder la resolución del problema hasta</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; que hayan pasado por lo menos 60 horas desde el envío de este</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mensaje. Gracias.</FONT>
</P>

<P><FONT SIZE=2>IMPORTANT: S'il vous plaît, attendez au minimum 60 heures après la</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; date de ce message avant de poster solutions, indices ou autres</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; révélations. Merci.</FONT>
</P>

<P><FONT SIZE=2>WICHTIG: Bitte schicken Sie keine Lösungen, Tipps oder Hinweise für</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; diese Aufgabe vor Ablauf von 60 Stunden nach dem Datum dieser</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Mail. Danke.</FONT>
</P>

<P><FONT SIZE=2>BELANGRIJK: Stuur aub geen oplossingen, hints of andere tips in de</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; eerste 60 uur na het verzendingstijdstip van dit</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bericht. Waarvoor dank.</FONT>
</P>

<P><FONT SIZE=2>VNIMANIE: Pozhalujsta ne shlite reshenija, nameki na reshenija, i</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; voobshe lyubye podskazki v techenie po krajnej mere 60 chasov</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ot daty etogo soobshenija.&nbsp; Spasibo.</FONT>
</P>

<P><FONT SIZE=2>Qing3 Zhu4Yi4: Qing3 Ning2 Deng3Dao4 Jie1Dao4 Ben3 Xin4Xi2 Zhi1Hou4 60</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Xiao3Shi2, Zai4 Fa1Biao3 Jie3Da2, Ti2Shi4, Huo4 Qi2Ta1 Hui4</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Xie4Lou4 Da2An4 De5 Jian4Yi4.&nbsp; Xie4Xie4.</FONT>
</P>
<BR>
<BR>
<BR>

<P><FONT SIZE=2>When I was in elementary school I wasted many an hour playing hangman with my friends. </FONT>
</P>

<P><FONT SIZE=2>The Game of Hangman</FONT>
<BR><FONT SIZE=2>--------------------</FONT>
</P>

<P><FONT SIZE=2>The goal of the game is to guess a word with a certain (limited) number of guesses. If we fail the &quot;man&quot; gets &quot;hanged,&quot; if we succeed he is set free. (We're not going to discuss the lesson's of life or justice this game teaches to the 8 year olds who play it regularly).</FONT></P>

<P><FONT SIZE=2>The game starts out with one person (not the player) choosing a &quot;mystery&quot; word at random and telling the player how many letters the mystery word contains. The player then guesses letters, one at a time, and the mystery word's letters are filled in until a) the entire word is filled in, or b) the maximum number of guesses are reached and the the player loses (man is hanged).</FONT></P>

<P><FONT SIZE=2>Write a perl program which lets the user play hangman. The program should take the following arguments: </FONT>
</P>

<P><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1) the dictionary file to use </FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2) the maximum number of guesses to give the player. </FONT>
</P>

<P><FONT SIZE=2>The program must then chose a mystery word from the dictionary file and print out as many underscores (&quot;_&quot;) as there are letters in the mystery word. The program will then read letters from the user one at a time. After each guess the program must print the word with properly guessed letters filled in. If the word has been guessed (all the letters making up the word have been guessed) then the program must print &quot;LIFE!&quot; and exit. If the word is not guessed before the maximum number of guesses is reached then the program must print &quot;DEATH!&quot; and exit.</FONT></P>

<P><FONT SIZE=2>Example interaction:</FONT>
</P>

<P><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; % ./hangman /usr/share/dict 5</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ___</FONT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bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ___</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ___</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m__</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DEATH!</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %</FONT>
</P>
<BR>

<P><FONT SIZE=2>NOTES</FONT>
<BR><FONT SIZE=2>- -----</FONT>
</P>

<P><FONT SIZE=2>1) The dictionary file will contain one word per line and use only</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp; 7-bit ASCII characters. It may contain randomly generated</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp; words. The dictionary will contain only words longer than 1</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp; character. The size of the dictionary may be very large.&nbsp; See</FONT>
</P>

<P><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <A HREF="http://perl.plover.com/qotw/words/" TARGET="_blank">http://perl.plover.com/qotw/words/</A></FONT>
</P>

<P><FONT SIZE=2>&nbsp;&nbsp; for sample word lists.</FONT>
</P>

<P><FONT SIZE=2>2) The dictionary file used for the test (or the program for</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp; generating it) will be made available along with the write-up.</FONT>
</P>

<P><FONT SIZE=2>3) If a letter appears more than once in the mystery word, all</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp; occurrences of that letter must be filled in. So, if the word is</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp; 'bokonon' and the player guesses 'o' the output must be '_o_o_o_'.</FONT>
</P>

<P><FONT SIZE=2>-Marco</FONT>
</P>
<BR>

</BODY>
</HTML>