Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: (Golf) Nearest Neighbors

by jmcnamara (Monsignor)
on Apr 04, 2001 at 13:36 UTC ( [id://69595]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    sub nn_single {
        @_=sort{$a<=>$b}@_;
        $_{abs$_[$_]-$_[$_-1]}=[$_-1,$_]for 1..$#_;
        @_[@{$_{(sort{$a<=>$b}keys%_)[0]}}]
    }
    
  2. or download this
    sub nn_dup {
        my$s=sub{sort{$a<=>$b}keys%_};
        @_{@_}=0;
    ...
        $_{abs$_[$_]-$_[$_-1]}=[$_-1,$_]for 1..$#_;
        @_[@{$_{(&$s)[0]}}]
    }
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-20 16:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found