Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
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 chilling in the Monastery: (10)
As of 2014-10-20 21:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (92 votes), past polls