Posts

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #351 (“Special Average” and “Arithmetic Progression”)

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-12-08 through 2025-12-14 is #351. The tasks for challenge #351 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 351-1: Special Average Submitted by: Mohammad Sajid Anwar You are given an array of integers. Write a script to return the average excluding the minimum and maximum of the given array. Example #1: Input: @ints = (8000, 5000, 6000, 2000, 3000, 7000) Output: 5250 Min: 2000 Max: 8000 Avg: (3000+5000+6000+7000)/4 = 21000/4 = 5250 Example #2: Input: @ints = (100_000, 80_000, 110_000, 90_000) Output: 95_000 Min: 80_000 Max: 110_000 Avg: (100_000 + 90_000)/2 = 190_000/2 = 95_000 Example #3: Input: @ints = (2500, 2500, 2500, 2500) Output: 0 Min: 2500 Max: 2500 Avg: 0 Example #4: Input: @ints = (2000) Output...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #350 (“Good Substrings” and “Shuffle Pairs”)

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-12-01 through 2025-12-07 is #350. The tasks for challenge #350 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 350-1: Good Substrings Submitted by: Mohammad Sajid Anwar You are given a string. Write a script to return the number of good substrings of length three in the given string. A string is good if there are no repeated characters. Example #1: Input: $str = "abcaefg" Output: 5 Good substrings of length 3: abc, bca, cae, aef and efg Example #2: Input: $str = "xyzzabc" Output: 3 Good substrings of length 3: "xyz", "zab" and "abc" Example #3: Input: $str = "aababc" Output: 1 Good substrings of length 3: "abc" Example #4: Input: $str = ...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #349 (“Power String” and “Meetings Point”)

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-11-24 through 2025-11-30 is #349. The tasks for challenge #349 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 349-1: Power String Submitted by: Mohammad Sajid Anwar You are given a string. Write a script to return the power of the given string. The power of the string is the maximum length of a non-empty substring that contains only one unique character. Example #1: Input: $str = "textbook" Output: 2 Breakdown: "t", "e", "x", "b", "oo", "k" The longest substring with one unique character is "oo". Example #2: Input: $str = "aaaaa" Output: 5 Example #3: Input: $str = "hoorayyy" Output: 3 Breakdown: "h"...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #348 (“String Alike” and “Convert Time”)

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-11-17 through 2025-11-23 is #348. The tasks for challenge #348 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 348-1: String Alike Submitted by: Mohammad Sajid Anwar Write a script to find out whether a given string can be split into two halves of equal lengths, each with the same non-zero number of vowels. Example #1: Input: "textbook" Output: false 1st half: "text" (1 vowel) 2nd half: "book" (2 vowels) Example #2: Input: "book" Output: true 1st half: "bo" (1 vowel) 2nd half: "ok" (1 vowel) Example #3: Input: "AbCdEfGh" Output: true 1st half: "AbCd" (1 vowel) 2nd half: "EfGh" (1 vowel) Example #4: Input: "rhyt...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #347 (“Format Date” and “Format Phone”)

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-11-10 through 2025-11-16 is #347. The tasks for challenge #347 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 347-1: Format Date Submitted by: Mohammad Sajid Anwar You are given a date in the form: 10th Nov 2025. Write a script to format the given date in the form: 2025-11-10 using the set below: @DAYS = ("1st", "2nd", "3rd", ....., "30th", "31st") @MONTHS = ("Jan", "Feb", "Mar", ....., "Nov", "Dec") @YEARS = (1900..2100) Example #1: Input: "1st Jan 2025" Output: "2025-01-01" Example #2: Input: "22nd Feb 2025" Output: "2025-02-22" Example #3: Input: "15th Apr...

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