Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

(boo) Re: Closest-value-in-list Golf!

by boo_radley (Parson)
on May 29, 2001 at 17:58 UTC ( #83928=note: print w/ replies, xml ) Need Help??


in reply to Closest-value-in-list Golf!

oops :
Warning: Use of "keys" without parens is ambiguous at C:\trash.pl line 8.
my answer is forthcoming, will update.
update you can shave off a few chars by changing

$h{shift@s}
to
$h{$s[0]}
. Don't get too complex, eh? UpdateTime's up!
sub e {sub n{abs($s-$b)};$s=pop;while($b=pop){if(&n<$d||!$d){$l=$b;$d= +&n}}$l}
for a total of 70 chars.


Comment on (boo) Re: Closest-value-in-list Golf!
Select or Download Code
Re: (boo) Re: Closest-value-in-list Golf!
by suaveant (Parson) on May 29, 2001 at 18:30 UTC
    even shorter to not assign to @s at all, like my Update2
                    - Ant
      sub g {$n=pop;$h{abs$_-$n}=$_ for@_;$h{(sort{$a<=>$b}keys%h)[0]}}

      57 if you take out the ( ) on the abs

      "Argument is futile - you will be ignorralated!"

        oooooohh... ++
                        - Ant

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://83928]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2014-12-18 18:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (59 votes), past polls