Posts

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #341 (“Broken Keyboard” and “Reverse Prefix”)

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-29 through 2025-10-05 is #341. The tasks for challenge #341 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 341-1: Broken Keyboard Submitted by: Mohammad Sajid Anwar You are given a string containing English letters only, and you are given a list of broken keys. Write a script to return the total words in the given sentence can be typed completely. Example #1 input: $str = 'Hello World', @keys = ('d') Expected output: 1 Example #2 input: $str = 'apple banana cherry', @keys = ('a', 'e') Expected output: 0 Example #3 input: $str = 'Coding is fun', @keys = () Expected output: 3 Example #4 input: $str = 'The Weekly Challenge', @keys = ('a','...

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...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #336 (“Equal Group” and “Final Score”)

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-08-25 through 2025-08-31 is #336 The tasks for challenge #336 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 336-1: Equal Group Submitted by: Mohammad Sajid Anwar You are given an array of integers. Write a script to return true if the given array can be divided into one or more groups: each group must be of the same size as the others, with at least two members, and with all members having the same value. Example #1: Input: @ints = (1,1,2,2,2,2) Output: true Groups: (1,1), (2,2), (2,2) Example #2: Input: @ints = (1,1,1,2,2,2,3,3) Output: false Groups: (1,1,1), (2,2,2), (3,3) Example #3: Input: @ints = (5,5,5,5,5,5,7,7,7,7,7,7) Output: true Groups: (5,5,5,5,5,5), (7,7,7,7,7,7) Example #4: Input: @ints ...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #335 (“Common Characters” and “TicTacToe”)

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-08-18 through 2025-08-24 is #335 The tasks for challenge #335 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 335-1: Common Characters Submitted by: Mohammad Sajid Anwar You are given an array of words. Write a script to return all characters that is in every word in the given array including duplicates. Example #1: Input: @words = ("bella", "label", "roller") Output: ("e", "l", "l") Example #2: Input: @words = ("cool", "lock", "cook") Output: ("c", "o") Example #3: Input: @words = ("hello", "world", "pole") Output: ("l", "o") Example #4: Input: ...