develooper Front page | | Postings from July 2002

Re: Golf this.

Thread Previous | Thread Next
July 15, 2002 23:33
Re: Golf this.
Message ID:
En op 16 juli 2002 sprak Tor Hildrum:
>> open F,$_[0];while(<F>){$h{$_}=$i;}foreach$k(%h){print"$k";}
>               ^^^^^
>Should be $ARGV[0]
> Yours removes duplicates but does not sort.
> How about this?
> #!perl -p
> $h{$_}=""}for(sort%h){
> Ah. :)
> {$h{$_}=""}for(sort%h){print}
>Gives an additional newline at the start though.

I do not understand. If my program gives different
output to the 'sort -u' command, please provide some
example test data showing where they differ.

> But, is this the shortest algorithm? Using a hash?
> 29 strokes?

I make it 25 strokes:
-p $h{$_}=""}for(sort%h){

I cannot answer if it is the shortest.
Only The Alien can answer that.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About