Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

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.

"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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://83972]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2018-04-24 23:12 GMT
Find Nodes?
    Voting Booth?