Hole type: subroutine
Write a subroutine that accepts a list of numbers, and returns the maximum number from the list, without using Perl's built-in sort.
Code | Length |
---|---|
sub hole {$m=pop;$m=($m,$_)[$m<$_]for@_;$m} | 32 |
sub hole {$m=pop;$_>$m&&($m=$_)for@_;$m} | 29 |
sub hole {$m=pop;$_>$m?$m=$_:1for@_;$m} | 28 |
This one is a nice, straightforward golf problem. Except for one thing; a correct solution requires initializing max with an element of the list. Otherwise, the subroutine fails when all the elements are negative.
At the tournament, one team tried initializing max to -999,999, but that wasn't low enough to fool the judging script. Sorry, no points!