Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Re: Re: (Golf) Nearest Neighbors

by satchboost (Scribe)
on Apr 05, 2001 at 00:23 UTC ( #69871=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: (Golf) Nearest Neighbors
in thread (Golf) Nearest Neighbors

This doesn't deal with duplicates. If you want to deal with duplicates, I think you change it to:

sub nn { @_{@_}=0;@_=sort{$a<=>$b}keys%_; $_[1]-$_[0]>$_[$_]-$_[$_-1]and@_[0,1]=@_[$_,$_-1]for 2..$#_; @_[0,1] }

That brings the total from 86 to 99. I'm not sure if the spec requires that duplicates be treated as one element or separate elements.


Comment on Re: Re: Re: (Golf) Nearest Neighbors
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (15)
As of 2015-07-28 14:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (256 votes), past polls