develooper Front page | perl.golf | Postings from July 2002

Re: Golf this.

Thread Previous | Thread Next
From:
Andrew.Savige
Date:
July 15, 2002 23:33
Subject:
Re: Golf this.
Message ID:
694BB7191495D51183A9005004C0B05452DE7E@ir-exchange-srv.ir.com.au
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


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