Posts

Showing posts from September, 2025

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #340 (“Duplicate Removals” and “Ascending Numbers”)

Image
For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two parts, with a new pair of tasks each Monday. You can find it here: The Weekly Challenge The Weekly Challenge for the week of 2025-09-22 through 2025-09-28 is #340. The tasks for challenge #340 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 340-1: Duplicate Removals Submitted by: Mohammad Sajid Anwar You are given a string consisting of lowercase English letters. Write a script to return the final string after all duplicate removals have been made. Repeat duplicate removals on the given string until we no longer can. A duplicate removal consists of choosing two adjacent and equal letters and removing them. Example #1: Input: 'abbaca' Output: 'ca' Step 1: Remove 'bb' => 'aaca' Step 2: Remove 'aa' => 'ca' Example #2: Input: 'azxxzy' Output: 'ay' Step 1: Remove 'xx...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #339 (Theme: “Maximum Overdrive”)

Image
For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two parts, with a new pair of tasks each Monday. You can find it here: The Weekly Challenge The Weekly Challenge for the week of 2025-09-15 through 2025-09-21 is #339 The tasks for challenge #339 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 339-1: Max Diff Submitted by: Mohammad Sajid Anwar You are given an array of integers having four or more elements. Write a script to find two pairs of numbers from this list (WITH 4 DISTINCT INDEXES WITHIN THE ARRAY) so that the difference between their products is maximum. Return the max difference. With Two pairs (a, b) and (c, d), the product difference is (a * b) - (c * d). Example 1 Input: (5, 9, 3, 4, 6) Output: 42 Pair 1: (9, 6) Pair 2: (3, 4) Product Diff: (9 * 6) - (3 * 4) => 54 - 12 => 42 Example 2 Input: (1, -2, 3, -4) Output: 10 Pair 1: (1, -2) Pair 2: (3, -4) Example 3 Inpu...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #338 (Theme: “Mad Max Beyond Perldome”)

Image
For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two parts, with a new pair of tasks each Monday. You can find it here: The Weekly Challenge The Weekly Challenge for the week of 2025-09-08 through 2025-09-14 is #338 The tasks for challenge #338 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 338-1: Highest Row Submitted by: Mohammad Sajid Anwar You are given a m x n matrix of real numbers. Write a script to find the highest row sum in the given matrix. ( # Example #1 input: [ [4, 4, 4, 4], [10, 0, 0, 0], [2, 2, 2, 9] ], # Expected output: 16 # Example #2 input: [ [1, 5], [7, 3], [3, 5] ], # Expected output: 10 # Example #3 input: [ [1, 2, 3], [3, 2, 1] ], # Expected output: 6 # Example #4 input: [ [2, 8, 7], [7, 1, 3], [1, 9, 5] ], # Expected output: 17 # Example #5 input: [ [10, 20, 30], [5, 5, 5], [0, 100, 0], [25, 25, 25] ], # Expected...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #337 (“Count LE Others” and “Count Odds”)

Image
For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two parts, with a new pair of tasks each Monday. You can find it here: The Weekly Challenge The Weekly Challenge for the week of 2025-09-01 through 2025-09-07 is #337 The tasks for challenge #337 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 337-1: Count LE Others Submitted by: Mohammad Sajid Anwar You are given an array of numbers, @num1. Write a script to return an array, @num2, where $num2[$i] is the count of all numbers in @num1 other than $num1[$i] which are less than or equal to $num1[$i]. Example #1: Input: @num1 = (6, 5, 4, 8) Output: (2, 1, 0, 3) Example #2: Input: @num1 = (7, 7, 7, 7) Output: (3, 3, 3, 3) Example #3: Input: @num1 = (5, 4, 3, 2, 1) Output: (4, 3, 2, 1, 0) Example #4: Input: @num1 = (-1, 0, 3, -2, 1) Output: (1, 2, 4, 0, 3) Example #5: Input: @num1 = (0, 1, 1, 2, 0) Output: (1, 3, 3, 4, 1) For each elemen...