in reply to Closest-value-in-list Golf!
66 chars with strict offsub g {$n=pop;$h{abs($_-$n)}=$_ for@_;@s=sort{$a<=>$b}keys%h;$h{shift@ +s};}
Update
oops trailing ; is extraneous... 65 strokes...sub g {$n=pop;$h{abs($_-$n)}=$_ for@_;@s=sort{$a<=>$b}keys%h;$h{shift@ +s}}
Update2 oooh!
59 strokessub g {$n=pop;$h{abs($_-$n)}=$_ for@_;$h{(sort{$a<=>$b}keys%h)[0]}}
|
---|
Replies are listed 'Best First'. | |
---|---|
(boo)Re: Re: Closest-value-in-list Golf -- or, a sorted affair.
by boo_radley (Parson) on May 29, 2001 at 18:38 UTC | |
by larryk (Friar) on May 29, 2001 at 18:47 UTC | |
by suaveant (Parson) on May 29, 2001 at 18:50 UTC | |
by boo_radley (Parson) on May 29, 2001 at 19:00 UTC | |
by suaveant (Parson) on May 29, 2001 at 19:10 UTC |