Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Closest-value-in-list Golf!

by jeroenes (Priest)
on May 29, 2001 at 19:12 UTC ( #83972=note: print w/ replies, xml ) Need Help??


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

I can offer a 47 36 char solution with the use of PDL:

sub i{my$a=pdl$_[0];minimum_ind(abs($a-$_[1]))}
and it is strict-compliant and very straightforward.

Of course it returns the index, but that is allowed, isn't it? Otherwise, add 4 chars to get the value.

Hey wait, do you only count the chars between {}? Than we can take of 7, that counts 40 chars. And there is room in the last part:

sub i{my$a=pdl$_[0];minimum_ind abs$a-pop}
And we are at 36 chars.

Jeroen
"We are not alone"(FZ)


Comment on Re: Closest-value-in-list Golf!
Select or Download Code
Re: Re: Closest-value-in-list Golf!
by Anonymous Monk on May 30, 2001 at 00:08 UTC
    Why do you not count "use PDL"?
      Should have mentioned that. Add 7 chars.

      Use of modules actually should disqualify a golf, methinks. It's just that I've come to like matrix calc, and couldn't resist such a solution.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://83972]
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: (11)
As of 2014-07-29 06:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (211 votes), past polls