in reply to (Golf) Nearest Neighbors
Why have a loop?
(75...)sub nn { my@x=@_[0,1];@_=sort{abs$x[0]-$x[1]<abs$a-$b or@x=($a,$b);$a<=>$b}@_;@ +x }
UPDATE
MeowChow pointed out that the parens for the arguments
of abs were not needed. That cut out 3 characters.
Plus by reversing the order of the comparison I managed
to substitute or for and, saving another. That makes it
71...
UPDATE 2
This is sick and slick.
Enjoy verifying that I am perfectly safe in using @_ as my temporary array. I think that 58 is the best I can do...sub nn { ()=sort{abs$_[0]-$_[1]<abs$a-$b or@_=($a,$b);$a<=>$b}@_;@_ }
UPDATE 3</B
petral sent me a /msg explaining how to remove 3 chars
from that solution. I would like to see him post that
since it was his idea, but until he does I want to note
that that solution can be beaten.
Replies are listed 'Best First'. | |
---|---|
Re: Re (tilly) 1: (Golf) Nearest Neighbors
by petral (Curate) on Apr 06, 2001 at 08:34 UTC | |
Re: Re (tilly) 1: (Golf) Nearest Neighbors
by MeowChow (Vicar) on Apr 05, 2001 at 01:03 UTC | |
Re: Re (tilly) 1: (Golf) Nearest Neighbors
by jmcnamara (Monsignor) on Apr 05, 2001 at 16:36 UTC | |
Re: Re (tilly) 1: (Golf) Nearest Neighbors
by bobione (Pilgrim) on Apr 05, 2001 at 17:38 UTC |
In Section
Obfuscated Code