Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Re: (Golf) Nearest Neighbors

by MeowChow (Vicar)
on Apr 04, 2001 at 23:45 UTC ( #69846=note: print w/replies, xml ) Need Help??

in reply to Re: (Golf) Nearest Neighbors
in thread (Golf) Nearest Neighbors

Very nice! Sniping one character gives:
sub nn { @_=sort{$a<=>$b}@_; $_[1]-$_[0]>$_[$_]-$_[$_-1]and@_[0,1]=@_[$_,$_-1]for 2..$#_; @_[0,1] }
The number to beat is 86...
               s aamecha.s a..a\u$&owag.print

Replies are listed 'Best First'.
Re: Re: Re: (Golf) Nearest Neighbors
by satchboost (Scribe) on Apr 05, 2001 at 00:23 UTC
    This doesn't deal with duplicates. If you want to deal with duplicates, I think you change it to:
    sub nn { @_{@_}=0;@_=sort{$a<=>$b}keys%_; $_[1]-$_[0]>$_[$_]-$_[$_-1]and@_[0,1]=@_[$_,$_-1]for 2..$#_; @_[0,1] }

    That brings the total from 86 to 99. I'm not sure if the spec requires that duplicates be treated as one element or separate elements.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://69846]
[stevieb]: Playing around with two DACs to control a single RGB LED (each DAC only has two outputs, LED has 3 inputs), and have realized that each of my IC RPi dists needs a wiring diagram, which is linked to within the documentation

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2017-08-20 19:29 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (317 votes). Check out past polls.