Posts

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #373 (“Equal List” and “List Division”)

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 2026-05-11 through 2026-05-17 is #373. The tasks for challenge #373 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 373-1: Equal List Submitted by: Mohammad Sajid Anwar You are given two arrays of strings. Write a script to return true if the two given array yield the same strings when joined; otherwise return false. I've reworded the above "description" to be much more unambiguous than the version on the web site. This is just a matter of joining and comparing. Robbie Hatley's Perl Solution to The Weekly Challenge 373-1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 373-2: List Division Submitted by: Mark Anderson You are given a list and a non-negativ...

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #372 (“Rearrange Spaces” and “Largest Substring”)

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 2026-05-04 through 2026-05-10 is #372. The tasks for challenge #372 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 372-1: Rearrange Spaces Submitted by: Mohammad Sajid Anwar You are given a string text of words that are placed among a number of spaces. Write a script to rearrange the spaces so that there is an equal number of spaces between every pair of adjacent words and that number is maximised. If you can’t distribute, place the extra spaces at the end. Finally return the string. I use this procedure: Count available spaces s. Trim leading and trailing spaces. Split string to @words on spaces. Count gaps between words (n words means n-1 gaps). Form quotient q and remainder r of sp...

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #371 (“Missing Letter” and “Subset Equilibrium”)

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 2026-04-27 through 2026-05-03 is #371. The tasks for challenge #371 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 371-1: Missing Letter Submitted by: Reinier Maliepaard You are given a sequence of 5 lowercase letters, with one letter replaced by ‘?’. Each letter maps to its position in the alphabet (‘a = 1’, ‘b = 2’, …, ‘z = 26’). The sequence follows a repeating pattern of step sizes between consecutive letters. The pattern is either a constant step (e.g., ‘+2, +2, +2, +2’) or a simple alternating pattern of two distinct steps (e.g., ‘+2, +3, +2, +3’). Example inputs: ("ac?gi", "ad?jm", "ae?mq", "acf?k", "beg?l") Expected outputs: e g i ...

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #370 (“Popular Word” and “Scramble String”)

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 2026-04-20 through 2026-04-26 is #370. The tasks for challenge #370 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 370-1: Popular Word Submitted by: Mohammad Sajid Anwar You are given a string paragraph and an array of banned words. Write a script to return the most popular word that is not banned. It is guaranteed there is at least one word that is not banned and the answer is unique. The words in paragraph are case-insensitive and the answer should be in lowercase. The words cannot contain punctuation symbols. Example #1: Inputs: [ "Bob hit a ball, the hit BALL flew far after it was hit.", ["hit"], ], Output: "ball" After removing punctuation and converting to lower...

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #369 (“Valid Tag” and “Group Division”)

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 2026-04-13 through 2026-04-19 is #369. The tasks for challenge #369 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 369-1: Valid Tag Submitted by: Mohammad Sajid Anwar You are given a given a string caption for a video. Write a script to generate tag for the given string caption in three steps as mentioned below: 1. Format as camelCase Starting with a lower-case letter and capitalising the first letter of each subsequent word. Merge all words in the caption into a single string starting with a #. 2. Sanitise the String Strip out all characters that are not English letters (a-z or A-Z). 3. Enforce Length If the resulting string exceeds 100 characters, truncate it so it is exactly 100 characters long. Example #1: I...

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #368 (“Make it Bigger” and “Big and Little Omega”)

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 2026-04-06 through 2026-04-12 is #368. The tasks for challenge #368 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 368-1: Make it Bigger Submitted by: Mohammad Sajid Anwar You are given a given a string number and a character digit. Write a script to remove exactly one occurrence of the given character digit from the given string number, resulting in the number being maximised. Example #1: Input: $str = "15456", $char = "5" Output: "1546" Removing the second "5" is better because the digit following it (6) is greater than 5. In the first case, 5 was followed by 4 (a decrease), which makes the resulting number smaller. Example #2: Input: $str = "7332", $char = ...

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #367 (“Max Odd Binary” and “Conflict Events”)

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 2026-03-30 through 2026-04-05 is #367. The tasks for challenge #367 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 367-1: Max Odd Binary Submitted by: Mohammad Sajid Anwar You are given a binary string that has at least one ‘1’. Write a script to rearrange the bits in such a way that the resulting binary number is the maximum odd binary number and return the resulting binary string. The resulting string can have leading zeros. Example 1 Input: $str = "1011" Output: "1101" Example 2 Input: $str = "100" Output: "001" Example 3 Input: $str = "111000" Output: "110001" Example 4 Input: $str = "0101" Output: "1001" Example 5 Input: $str =...