Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
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 cooling their heels in the Monastery: (15)
As of 2015-07-06 21:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (83 votes), past polls