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

Re: (Golf) Nearest Neighbors

by jmcnamara (Monsignor)
on Apr 04, 2001 at 13:36 UTC ( #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
Node Status?
node history
Node Type: note [id://69595]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2014-09-19 08:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (133 votes), past polls