[kw-pm] Last night's meeting

John Macdonald john at perlwolf.com
Fri Jun 19 08:39:38 PDT 2009


On Fri, Jun 19, 2009 at 11:29:20AM -0400, John Macdonald wrote:
> On Fri, Jun 19, 2009 at 11:15:57AM -0400, John Macdonald wrote:
> > On Fri, Jun 19, 2009 at 10:55:25AM -0400, Daniel R. Allen wrote:
> > > ...We had considered the ?:1 operator, on the board, but didn't see where
> > > it got us. Clearly we didn't stare at it long enough.
> > > 
> > > But turning rand()<1/++$n into rand++$n<1 into rand$.<1 is sheer genius
> > > on both of your parts. Nicely done, John and Raymond.
> > > 
> > > 29 strokes == winner?
> > 
> > In my previous message, I talked about "cheating" by providing
> > executable code that is not part of the char count in various
> > ways (-M switch, and the filename).
> > 
> > But that trick I played on the -n switch made me realize that
> > using -n is similarly a cheat because it provides code that is
> > not counted.
> > 
> > So what is the best non-cheating char count?
> > 
> > $ perl -e '@a=<>;print at a[rand(@a)]' <alpha.html
> > 
> > That's better than the "cheating" we've been doing using -n!
> > 
> > And then, it can be golfed down a bit more to:
> > 
> > $ perl -e 'print at a[rand(@a=<>)]' <alpha.html
> > 
> > 
> > So, that's down to 18 chars, with no supporting cheats of any kind.
> 
> However, I haven't seen the original challenge - does it require
> that the program handle input that is too large to fit in memory?

While I was writing that, two people were pointing out that
the handling it as a stream was part of the rules.  The best
"no outside assistance" for I can come up with so far is:

$ perl -e 'rand$.<1?$a=$_:1for<>;print$a' <alpha.html

which is 29 chars.  The warn trick can help here (but that
is using some extra shell assistance to move STDERR back
to STDOUT):

$ perl -e 'rand$.<1?$a=$_:1for<>;warn$a' 2>&1 <alpha.html

(Note, this is an improvement if you add the extra code provided
by the -n or -p switch, even assuming that extraneous blanks
aren't counted.)


More information about the kw-pm mailing list