I was reading about the PGA Tournament today:

        http://www.perlmonks.org/?node_id=82878&foo=Refresh

That's the Perl Golf Apocalypse.  The tournament consists of 17 "holes", and
the golfers' goal is to reach the hole in the minimum number of (key)
strokes.

Here are some of the holes:

        Hole 1 - Fifth Word 

        Write a function which returns the fifth word in a string. A word is
any 
        sequence of letters, numbers, and/or underscores. The string will be

        passed as the sole argument and will contain at least 5 words. 
        
        Par: 3 minutes (Difficulty: Easy)

So let's play.  Rules:

        *  A stroke is a character.  All characters count.
        *  Buggy entries are discounted.  A entry is not considered buggy if

           the spec can be reasonably interpreted to describe it (IOW, you
           are not penalized for ambiguous specifications.)
        *  Program will be run under jconsole -jprofile
                *  That is, it may not rely on any libraries or pre-defined
names 
                   (excepting y, which is the name of the argument).
        *  You may submit alternative entries that rely on external
libraries, 
           if they're interesting.  Alternative entries are discounted.
        *  No I/O.  Stay entirely within the interpreter. 

Here's my initial entry for Hole 1 (spoiler alert)      
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
        8{y];.1~1,2~:/\2|'/9...@z^_`z'I.y

at 30 chars.  For comparison, expressed as a tacit verb, we have
(8{]];.1~1,2~:/\2|''/9...@z^_`z''&I.)y  which is 33 characters.

In case it's not clear,  2|'/9...@z^_`z'&I.  uses interval-index to classify
the word-characters, without calling each out explicitly.  But that's the
only interesting part of the expression, so I feel it can be improved
(shortened).

-Dan



----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to