note
chipmunk
I disagree with [tilly] that using sort() is the natural solution. I think <i>this</i> is the natural solution:
<code>sub closest {
$n=pop;$c=pop;abs$n-$_<abs$n-$c?$c=$_:0for@_;$c
}
</code>
This is O(n) rather than O(n*log n). Of course, at 47 characters it is, unfortunately, a longer solution. Oh well!
83923
83923