in reply to (Golf) Hangman Player

Here's part 1:
#! /usr/bin/perl -w use strict; open WORDS,"</usr/dict/words"; my @words = (<WORDS>); close WORDS; my @guessed = qw(a b c r l); my @matches = f("__rl",\@words,\@guessed); print foreach (@matches); #-------------------------------------- sub f{ my ($guess,$wordref,$letterref) = @_; my @m = (); my $alphabet = join"|",('a'..'z'); my $guessed = join"|",@$letterref; $alphabet =~ s/$guessed//g; $guess =~ s!_![$alphabet]!g; foreach (@$wordref) { push @m,$_ if (/\b$guess\b/) } return @m; } #--------------------------------------
OK, it's not very short but it does the job. I'll have a go at part 2 this evening.

JJ

Replies are listed 'Best First'.
Re: Re: (Golf) Hangman Player
by dragonchild (Archbishop) on Oct 04, 2001 at 20:09 UTC
    Using your framework, I got f() down to 97.
    ($a=join"|",a..z)=~s/join"|",@{pop@_}//eg;($g=shift)=~s!_![$a]!g;/^$g$ +/&&push@m,$_ for@{pop@_};@m
    If I could change the order of the arguments, I could cut 2 characters by make the shift a pop. I am a little perplexed as to why @{pop@_} won't let me do a @$_[0], which would cut another 3 characters. *shrugs*

    Update: I feel slightly inadequate after reading japhy's contributions. *sighs*

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

      The reason is this:
      @$_[0] => @{$_}[0] => (@$_)[0]

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