PWC 231
PWC 231 Two easy challenges this week. It is tempting to try them in Perl 5, Raku as well as Julia, but alas, I don't have the time. So here goes Perl 5 only. Challenge 1 (Min Max) We are given a list of distinct integers and asked to return the elements that are neither the maximum nor the minimum. If there are no such elements, then return -1. That happens if the list length is 2 or less, in which case every element is perforce either a maximum or minimum or both. I sort the list and return the elements between the head and the tail. I use PDL. Here is the key subroutine: sub min_max { my $ints=pdl(@_)->uniqvec; ($ints->dim(0) > 2) ? ($ints->qsort->(1:(($ints->dim(0))-2))) : (-1); } Just in case the input is not a list of distinct integers, I force it to its unique elements using the PDL uniqvec method. I then check if the length is 2 or less, in which case we return -1, else we sort and return the sub-piddle between the head and tail