Why have a loop?
sub nn {
my@x=@_[0,1];@_=sort{abs$x[0]-$x[1]<abs$a-$b or@x=($a,$b);$a<=>$b}@_;@
+x
}
(75...)
UPDATE
MeowChow pointed out that the parens for the arguments
of abs were not needed. That cut out 3 characters.
Plus by reversing the order of the comparison I managed
to substitute or for and, saving another. That makes it
71...
UPDATE 2
This is sick and slick.
sub nn {
()=sort{abs$_[0]-$_[1]<abs$a-$b or@_=($a,$b);$a<=>$b}@_;@_
}
Enjoy verifying that I am perfectly safe in using @_ as my
temporary array. I think that 58 is the best I can do...
UPDATE 3</B
petral sent me a /msg explaining how to remove 3 chars
from that solution. I would like to see him post that
since it was his idea, but until he does I want to note
that that solution can be beaten.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.