PWC 200
PWC 200 This week again, due to work pressures, I have done the challenges only in Perl 5 and Raku, not in the guest language Julia. Challenge 1 (Arithmetic Slices) Given a list of integers, we are asked to find all slices of the list (sub-lists of consecutive elements) that have at least three elements, and where the difference between every consecutive element is the same. This is a one-liner in Raku . raku -e '(0 .. @*ARGS-1).combinations(2).grep({@_[1]-@_[0]>1}).map({@*ARGS[@_[0]..@_[1]]}).grep( {my @n=@_; (0 .. @n-3).map( {(@n[$_+1]-@n[$_]) == (@n[$_+2]-@n[$_+1])} ).sum==(@n.elems-2) } ).say' $@ The steps are: Get all slices by getting all combinations of two elements (bounds of the slice) Restrict to slices that are at least three elements long (difference between the slice bounds is greater than 1) Map the pairs of bounds to get slices from the list Use grep to check if the condition is true for each slice: For each slice, loop through the slice, checking that the dis...