Robbie Hatley's Perl Solutions To The Weekly Challenge #202
For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle, usually with two parts, cycling every Sunday. You can find it here: The Weekly Challenge This week (2023-01-29 through 2023-02-04) is weekly challenge #202. Task 1 I found super easy: "You are given an array of integers. Write a script to print 1 if there are 3 consecutive odds in the given array; otherwise print 0." The sub I wrote to do that was just a few simple lines which I wrote in 5 minutes flat: sub tco (@a){ for (my $i = 0 ; $i <= $#a-2 ; ++$i){ if ( !($a[$i+0]%2) ) {$i += 0; next;} if ( !($a[$i+1]%2) ) {$i += 1; next;} if ( !($a[$i+2]%2) ) {$i += 2; next;} return 1;} return 0;} Task 2, however, I found much more challenging: "Given a profile as a list of altitudes, return the leftmost widest valley. A valley is defined as a subarray of the profile consisting of two parts: the first part is non-increasing and the second part...