Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #306 ("Odd Sum" and "Last Element")
For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two parts, cycling every Sunday. You can find it here: The Weekly Challenge The Weekly Challenge for the week of 2025-01-27 through 2025-02-02 is #306. The tasks for challenge #306 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 306-1: "Odd Sum" Submitted by: Mohammad Sajid Anwar You are given an array of positive integers, @ints. Write a script to return the sum of all possible odd-length subarrays of the given array. A subarray is a contiguous subsequence of the array. Example #1: Input: @ints = (2, 5, 3, 6, 4) Output: 77 Odd length sub-arrays: (2) => 2 (5) => 5 (3) => 3 (6) => 6 (4) => 4 (2, 5, 3) => 10 (5, 3, 6) => 14 (3, 6, 4) => 13 (2, 5, 3, 6, 4) => 20 Sum => 2 + 5 + 3 + 6 + 4 + 10 + 14 + 13 + 20 => 77 Example #2: Input: @ints = (1, 3) Output: 4 I'll solve this problem by using nest...