Posts

Showing posts from October, 2025

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #343 (“Zero Friend” and “Champion Team”)

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-10-13 through 2025-10-19 is #343. The tasks for challenge #343 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 343-1: Zero Friend Submitted by: Mohammad Sajid Anwar You are given a list of numbers. Find the number that is closest to zero and return its distance to zero. Example #1: Input: (4, 2, -1, 3, -2) Output: 1 Example #2: Input: (-5, 5, -3, 3, -1, 1) Output: 1 Example #3: Input: (7, -3, 0, 2, -8) Output: 0 Example #4: Input: (-2, -5, -1, -8) Output: 1 Example #5: Input: (-2, 2, -4, 4, -1, 1) Output: 1 I store an ascending numeric sort of the absolute values of the given numbers in an array, then return the 0th element of that array. Robbie Hatley's Perl Solution ...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #345 (“Peak Positions” and “Last Visitor”)

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-10-27 through 2025-11-02 is #345. The tasks for challenge #345 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 345-1: Peak Positions Submitted by: Mohammad Sajid Anwar You are given an array of real numbers. Find all the peaks in the array. (A "peak" is an element that is strictly greater than its left and right neighbours.) Return the indices of all such peak positions. Example #1: Input: (1, 3, 2) Output: (1) Example #2: Input: (2, 4, 6, 5, 3) Output: (2) Example #3: Input: (1, 2, 3, 2, 4, 1) Output: (2, 4) Example #4: Input: (5, 3, 1) Output: () Example #5: Input: (1, 5, 1, 5, 1, 5, 1) Output: (1, 3, 5) To solve this problem, I riffle through the middle ...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #344 (“Array Form Compute” and “Array Formation”)

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-10-20 through 2025-10-26 is #344. The tasks for challenge #344 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 344-1: Array Form Compute Submitted by: Mohammad Sajid Anwar You are given an array of integers, @ints and an integer, $x. Write a script to add $x to the integer in the array-form. The array form of an integer is a digit-by-digit representation stored as an array, where the most significant digit is at the 0th index. Example 1 Input: @ints = (1, 2, 3, 4), $x = 12 Output: (1, 2, 4, 6) Example 2 Input: @ints = (2, 7, 4), $x = 181 Output: (4, 5, 5) Example 3 Input: @ints = (9, 9, 9), $x = 1 Output: (1, 0, 0, 0) Example 4 Input: @ints = (1, 0, 0, 0, 0), $x = 9999 Output: (1, 9, 9, 9, 9) Example 5 Inpu...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #343 (“Zero Friend” and “Champion Team”)

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-10-13 through 2025-10-19 is #343. The tasks for challenge #343 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 343-1: Zero Friend Submitted by: Mohammad Sajid Anwar You are given a list of numbers. Find the number that is closest to zero and return its distance to zero. Example #1: Input: (4, 2, -1, 3, -2) Output: 1 Example #2: Input: (-5, 5, -3, 3, -1, 1) Output: 1 Example #3: Input: (7, -3, 0, 2, -8) Output: 0 Example #4: Input: (-2, -5, -1, -8) Output: 1 Example #5: Input: (-2, 2, -4, 4, -1, 1) Output: 1 I store an ascending numeric sort of the absolute values of the given numbers in an array, then return the 0th element of that array. Robbie Hatley's Perl Sol...

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