On Tue, Jul 31, 2001 at 05:42:56PM +1000, [EMAIL PROTECTED] wrote:
> I noticed an interesting golf example at:
> http://www.sysarch.com/perl/golf/example.text
> 
> "You want to find words with exactly ten non-repeating letters
> such as 'binoculars', 'fishmonger', or 'paintbrush', suitable
> for games or simple encryption of numbers where every decimal
> digit is represented by a letter."
> 
> For this game, I created my own words file like this:
>  egrep -v "[^a-z]" /usr/dict/words > words
> to ensure no capital letters and no hyphens, just plain
> lowercase words.
> 
> The best score posted on the above web page was:
>  perl -pe'$_=""if/(.).*\1/||11-length' words
> So far, I have been able to reduce this by 2 characters.
> Can anyone do better?
> 
> BTW, does there exist a set of standard Perl golf rules?
> What about a database of classic Perl golf games?
> 
> Contributions/improvements to any of the sections
> below are welcome.
> 
> Open
> ----
> perl -ne'y///c-11|/(.).*\1/||print' words
> perl -pe'$_=""if/(.).*\1/|y///c-11' words
> perl -ne'print if/^.{10}$/&!/(.).*\1/' words
> perl -pe'$_=""if/^(?!.{10}$)|(.).*\1/' words
> perl -pe's/^(?!.{10}\n).*$|^.*(.).*\1.*$//s' words
> 
> No RegExs
> ---------
> perl -anF// -e'@F{%F=@F}=0;121-@F*keys%F||print' words
> perl -ne'@g{%g=@g=/./gs}=0;121-@g*keys%g||print' words

I'd say that /./s is a regex and hence this entry is disqualified in
the No RegEx category.

> perl -anF// -e'121-@F*keys%{{map{$_,0}@F}}||print' words

Of course, all entries using -F// are fishy:

    perl -MO=Deparse -anF// -ce'@F{%F=@F}=0;121-@F*keys%F||print'
    LINE: while (defined($_ = <ARGV>)) {
        @F = split(//, $_, 0);
        @F{%F = @F} = 0;
        print $_ unless 121 - @F * keys(%F);
    }
    -e syntax OK


Here's one without any regexes:

    perl -nle'$x=$:=$_;map$$x{chop$:}=1,0..9;keys%$x>9&10==y&&&c&&print' words


Abigail

Reply via email to