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

Re: (Golf) Nearest Neighbors

by MeowChow (Vicar)
on Apr 05, 2001 at 00:39 UTC ( #69879=note: print w/ replies, xml ) Need Help??

in reply to (Golf) Nearest Neighbors

A bit late, considering tilly's death-blow, er... swing, but here's one that merlyn might appreciate, weighing in at 84 chars:

sub nn { my($p,@l)=sort{$a<=>$b}@_;@{(sort{$$a[0]<=>$$b[0]}map[$_-$p,$p+0,$p= +$_],@l)[0]}[1,2] }
               s aamecha.s a..a\u$&owag.print

Comment on Re: (Golf) Nearest Neighbors
Download Code
Re: Re: (Golf) Nearest Neighbors
by thospel (Hermit) on Oct 27, 2003 at 19:28 UTC
    Just saw this thread. Here is a destructive (only works once) solution at 46:

    sub nn{$a|=$"x$_.1for@_;$b.=$"until$a=~/1$b(1)/;@a=@-}

      Ah, I should think a bit more before submitting. Here is a 44 (and I should also mention it only works for smallish natural numbers, all different and at least 2 arguments):

      sub nn{$a|=2x$_.3for@_;$b.=2until$a=~/3$b(3)/;@a=@-}

      The need for the assign is a perlbug, otherwise it would be 41

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (16)
As of 2015-03-30 13:08 GMT
Find Nodes?
    Voting Booth?

    When putting a smiley right before a closing parenthesis, do you:

    Results (644 votes), past polls