Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2019-06-17 00:36 GMT
Find Nodes?
    Voting Booth?
    Is there a future for codeless software?

    Results (76 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!