develooper Front page | perl.fwp | Postings from December 2001

Re: Santa Hole 5 (wc.pl) Post Mortem

Thread Previous | Thread Next
From:
Tim Ayers
Date:
December 8, 2001 04:28
Subject:
Re: Santa Hole 5 (wc.pl) Post Mortem
Message ID:
lmge680y.fsf@tim.reuters.com
>>>>> "R" == Rick Klement <rklement@pacbell.net> writes:
R> Since I'm going through "Golf withdrawal":

No kidding. As an alternative to cold turkey, I've wasted a little
time with the following...

Given Andrew's Post Mortem listings of everyone's solutions, print out
each unique solution sorted in ascending length. Assume the list is
normalized such that the she-bang line is #!perl, i.e. run the list
thru "perl -pe's/#!.*perl/#!perl/'" before dealing with it.

I have two variations one stroke different from each other.

perl\
 -ne'/ \d+/?$c=!($a{$c}=$&):($c.=$_);END{print sort{$a{$b}<=>$a{$a}}keys%a}'

perl\
 -ne'/^-/?$c=$a{$c}="":($c.=$_);END{print sort{length$b<=>length$a}keys%a}'

I'm sure there are smarter approaches that I don't see. Something with
the flip-flop maybe, but I'm not bright enough to use that beyond
"11..exit".

Hope you have a very nice day, :-)
Tim Ayers (tim.ayers@reuters.com)


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About