Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

(tye)Re: (Golf) Nearest Neighbors

by tye (Sage)
on Apr 04, 2001 at 22:32 UTC ( [id://69781]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    sub nn{my$x=pop;(sort{$b<=>$a}map{abs($_-$x)}@_)[0,1]}
    
  2. or download this
    sub nn{my$x=pop;
      (map$_->[0],sort{$a->[1]<=>$b->[1]}map[$_,abs$_-$x],@_)[0,1]}
    # or
    sub nn2{my$x=pop;
      my@d=map abs$_-$x,@_;@_[(sort{$d[$a]<=>$d[$b]}0..$#_)[0,1]]}
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://69781]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-03-29 05:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found