This is O(n) rather than O(n*log n). Of course, at 47 characters it is, unfortunately, a longer solution. Oh well!sub closest { $n=pop;$c=pop;abs$n-$_<abs$n-$c?$c=$_:0for@_;$c }
In reply to Re: Closest-value-in-list Golf!
by chipmunk
in thread Closest-value-in-list Golf!
by larryk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |