Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Closest-value-in-list Golf!

by jeroenes (Priest)
on May 29, 2001 at 19:12 UTC ( [id://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)

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://83972]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-23 22:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found