Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

(tye)Re: (Golf) Nearest Neighbors

by tye (Sage)
on Apr 04, 2001 at 22:32 UTC ( #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
Node Status?
node history
Node Type: note [id://69781]
help
Chatterbox?
[beech]: thank you, it sure is pretty "code", yup, thats what I call it my ...
beech .oO( talking 'bout my ...)

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (10)
As of 2017-02-28 08:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (398 votes). Check out past polls.