Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

(boo)Re: Re: Closest-value-in-list Golf -- or, a sorted affair.

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


in reply to Re: Closest-value-in-list Golf!
in thread Closest-value-in-list Golf!

sort{$a<=>$b}keys%h
is too much, since $a<=>$b is the default sort. that leaves you with
sub g {$n=pop;$h{abs($_-$n)}=$_ for@_;$h{(sort keys%h)[0]}}
for 52.


Comment on (boo)Re: Re: Closest-value-in-list Golf -- or, a sorted affair.
Select or Download Code
Re: (boo)Re: Re: Closest-value-in-list Golf -- or, a sorted affair.
by larryk (Friar) on May 29, 2001 at 18:47 UTC
    did you test this? i think you'll find that $a cmp $b is the default.

    "Argument is futile - you will be ignorralated!"

Re: (boo)Re: Re: Closest-value-in-list Golf -- or, a sorted affair.
by suaveant (Parson) on May 29, 2001 at 18:50 UTC
    Test your code...

    that does not work... I tried it already... returns 20
                    - Ant

      How strange. I was using a different data set when I tested this, and it returned the correct answer.

      Mea culpa.

        Must be the decimals or something... I thought it would work, too
                        - Ant

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2014-08-30 11:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (293 votes), past polls