Hey,
Someone on IRC asked me about this... I'm not fully aware of Golf rules so be gentle :) this is my first shot at it.
#!/usr/bin/perl $w='foobar';@w=split//,$w;for$a(0..7){$z=$a;print"guess\n";$_=<>;chomp +;$l{$_}++;@l=map{$f=$l{$_}?$_:"_"}@w;if(!grep{!$l{$_}}@w){last;}print +@l,$/;}print$z==7?'boo':'congrats'
This is about 190 chars... shebang included. It can be tweaked by reducing the hardcoded 'boo' and 'congrats'. No fancy graphics...

Greetz
Beatnik
... Quidquid perl dictum sit, altum viditur.

Replies are listed 'Best First'.
Re: (Golf) Hangman
by japhy (Canon) on Aug 29, 2001 at 00:16 UTC
    Well, here's my approach. I include some diagnostic information (the word thus far and the guesses left), and I only subtract a guess when a letter is not found.
    # size: 42 * 3 = 126 #23456789_123456789_123456789_123456789_12 # @ARGV = (phrase, guesses) $g=pop;@x=split//,pop;@s{@x}=(_)x@x;$"=""; while($g){print"@s{@x} $g:";<>=~/./;$s{$&} =$&;$g-="@x"!~$&;"@s{@x}"=~/_/&&exit}die@x

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Re: (Golf) Hangman
by dragonchild (Archbishop) on Aug 29, 2001 at 00:00 UTC
    Feh. Standard golfing got down to 157 (you don't count the shebang line) while keeping the boo and congratz and the like.

    However, a good golf would be something that can be written into a function. So, maybe if you changed it so that the result of hangman'ing is return as a 1 or 0 and all the strings are either handled by the caller or passed in. In that spirit, I give you 134 :

    sub h { @w=pop=~/./g;for$a(1..pop){print$_[0],$/;$_=<>;chop;$l{$_}++;@l=map{$l +{$_}?$_:'_'}@w;print@l,$/;return 1if!grep{!$l{$_}}@w} } if (h('guess', 7, 'foobar')) { print "Congratz!\n"; } else { print "Boo!\n"; }

    ------
    /me wants to be the brightest bulb in the chandelier!

    Vote paco for President!

Re: (Golf) Hangman
by tachyon (Chancellor) on Aug 29, 2001 at 19:21 UTC

    Not the shortest but what can you expect with all those snazzy graphics ;-)

    sub hangman { @w=split//,pop;@w{@w}=("-")x@w;@h=split$","______ | |\n |\n |\n |\n __ +____\n";$d="______\n| |\n| _O_\n| |\n| / \\\n|______";while($g<8){p +rint@h[reverse 0..$g-1],$/,@w{@w},"$/?";$_=<>;chop;$w{$_}?$w{$_}=$_:$ +g++;(join"",values%w)!~/-/&&last}print$g<8?@w:$d } hangman("Hangman");

    If you ditch the graphics it comes in at 125 (122 without the ? prompt)

    sub hangman { @w=split//,pop;@w{@w}=("-")x@w;while($g<8){print@w{@w},"$/?";$_=<>;cho +p;$w{$_}?$w{$_}=$_:$g++;(join"",values%w)!~/-/&&last}$g } print hangman("Hangman")<8 ? "Winner!" : "RIP";

    Update

    Borrowing a couple of japhy's ideas 110 strokes

    sub hangman { @w=split//,pop;@w{@w}=("-")x@w;while($g<8){print@w{@w},$/;<>=~/./;$w{$ +&}?$w{$&}=$&:$g++;"@w{@w}"!~/-/&&last}$g }

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print