http://www.perlmonks.org?node_id=69694


in reply to (Golf) Nearest Neighbors

While this may not have many new ideas, it does weigh in at 117 characters and deal with dups:
sub nn2 { my$s=sub{sort{$a<=>$b}keys%_}; @_{@_}=0;@_=&$s;%_=(); $_{abs($_[$_]-$_[$_+1])}=[@_[$_,$_+1]]for 0..$#_; @{$_{(&$s)[0]}} }

Neat problem!