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

No RegExs and No Hashes
-----------------------
perl -anF// -e'grep($_ ne$p&&($p=$_),sort@F)*@F-121||print' words
perl -anF// -e'$_=join"",sort@F;y///cs;y///c*@F-121||print@F' words

Artistic
--------
perl -anF// -e '@F{%F=@F}=F;242-@F*@{[%F]}||print@F' words
perl -lne '@g=%g=/./g;$g=2;5*$g-@g||(@g{@g}=@g)!=@{[%g]}/$g or print@g'
words

Non-Perl
--------
grep '^..........$' words|grep -v '\(.\).*\1'

Andrew.

Reply via email to