<?xml version="1.0" encoding="windows-1252"?>
<node id="83991" title="Re: Closest-value-in-list Golf!" created="2001-05-29 16:26:45" updated="2005-07-19 14:08:39">
<type id="11">
note</type>
<author id="43546">
chipmunk</author>
<data>
<field name="doctext">
I disagree with [tilly] that using sort() is the natural solution.  I think &lt;i&gt;this&lt;/i&gt; is the natural solution:
&lt;code&gt;sub closest {
$n=pop;$c=pop;abs$n-$_&lt;abs$n-$c?$c=$_:0for@_;$c
}
&lt;/code&gt;
This is O(n) rather than O(n*log n).  Of course, at 47 characters it is, unfortunately, a longer solution.  Oh well!</field>
<field name="root_node">
83923</field>
<field name="parent_node">
83923</field>
</data>
</node>
