Posts

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

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #366 (“Count Prefixes” and “Valid Times”)

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-23 through 2026-03-29 is #366. The tasks for challenge #366 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 366-1: Count Prefixes Submitted by: Mohammad Sajid Anwar You are given an array of words and a string (contains only lowercase English letters). Write a script to return the number of words in the given array that are a prefix of the given string. ( # Example #1 input: [["a", "ap", "app", "apple", "banana"], "apple"], # Expected output: 4 # Example #2 input: [["cat", "dog", "fish"], "bird"], # Expected output: 0 # Example #3 input: [["hello", "he", "hell...

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #365 (“Alphabet Index Digit Sum” and “Valid Token Counter”)

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-16 through 2026-03-22 is #365. The tasks for challenge #365 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 365-1: Alphabet Index Digit Sum Submitted by: Mohammad Sajid Anwar You are given a string $str consisting of lowercase English letters, and an integer $k. Write a script to convert a lowercase string into numbers using alphabet positions (a=1 … z=26), concatenate them to form an integer, then compute the sum of its digits repeatedly $k times, returning the final value. Example 1 input: $str = "abc", $k = 1 Expected output: 6 Example 2 input: $str = "az", $k = 2 Expected output: 9 Example 3 input: $str = "cat", $k = 1 Expected output: 6 Example 4 input: $str = "dog...

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #364 (“Decrypt String” and “Goal Parser”)

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-09 through 2026-03-15 is #364. The tasks for challenge #364 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 364-1: Decrypt String Submitted by: Mohammad Sajid Anwar You are given a string formed by digits and ‘#'. Write a script to map the given string to English lowercase characters given the following two rules: 1: Characters 'j' to 'z' are represented by '10#' to '26#'. 2: Characters 'a' to 'i' are represented by '1' to '9'. Example #1: Input: $str = "10#11#12" Output: "jkab" Example #2: Input: $str = "1326#" Output: "acz" Example #3: Input: $str = "25#24#123" Output: "yxabc" ...

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #363 (“String Lie Detector” and “Subnet Sheriff”)

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-02 through 2026-03-08 is #363. The tasks for challenge #363 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 363-1: String Lie Detector Submitted by: Mohammad Sajid Anwar You are given a string. Write a script that parses a self-referential string and determines whether its claims about itself are true. The string will make statements about its own composition, specifically the number of vowels and consonants it contains. ( # Example #1 input: "aa — two vowels and zero consonants", # Expected output: true # Example #2 input: "iv — one vowel and one consonant", # Expected output: true # Example #3 input: "hello - three vowels and two consonants", # Exp...