Phil Carmody wrote:
> 
> --- Rick Klement <[EMAIL PROTECTED]> wrote:
> > Phil Carmody wrote:
> > >
> > > 2) In 2 days time, I'm going to want some pointers from the gurus
> > on
> > > the no doubt obvious tweaks that I could make to my hamming entry
> > -
> > > is this the place for such discussions?
> >
> > Pointer: drop characters when the code works just as well without
> > them:
> 
> $_=pop;$c.=$w++&$w?(s///,$f^=$w*$&,$&):2while/./;$c=~s|2|1&$f/$+[0]|eg;print"$c
> "
> 
> from
> 
> $_=pop;$c.=$w++&$w?(s/.//,$f^=$w*$&,$&):2while/./;$c=~s|2|1&$f/$+[0]|eg;print"$c
> "
> 
> Well I never knew that! At least one character wasn't going to change
> my position, you lot at the top had a fair safety margin protecting
> you from us earthlings.

I find things I don't know all the time. In this golf I found the /s on a
regex doesn't always go where you might think it would, that:

$@^=($@[@@+!(@@&@@+1)]=$_)*@@for$,,pop=~/./g;print/./s?$_:$@>>$-++&1for@@,$/

shortens to:

$@^=($@[@@+!(@@&@@+1)]=$_)*@@for$,,pop=~/./gs;print//?$_:$@>>$-++&1for@@,$/

and *not*:

$@^=($@[@@+!(@@&@@+1)]=$_)*@@for$,,pop=~/./g;print//s?$_:$@>>$-++&1for@@,$/

> And Ton - I can't say I know what -l is all about, I read the fine
> manpage, but as someone who's never once used $/ or $\ the
> description fell a bit flat.
> 
> The only solution is to use them more...

Or study the post-mortems from previous games. I always recommend golfers
study Eugene's rev.pl from Andrew's Santa Challenge: "print the lines from
an input file in reverse order". Almost everyone found the simple, short,
clean, and straightforward solution:

print reverse<>

but Eugene saved two strokes with:

-p $\=$_.$\}{

Studying this solution gives insight not only to how $\ works, but how -p
is structured, how to avoid using the word "print", and even what exactly
is printed by a bare "print" without an argument.

Also, the winning cantor.pl from TPR03 used $\ instead of $_ to save
tie-breaker points.

> 
> Cheers guys, I'm most impressed.
> 
> I shall be coming back for more punishment in the next one :-)

You did extremely well for a first golf entry, congratulations!

-- 
Rick Klement

Reply via email to