Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #330 (“Clear Digits” and “Title Capital”)
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 for the week of 2025-07-14 through 2025-07-20 is #330
The tasks for challenge #330 are as follows:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 330-1: Clear Digits Submitted by: Mohammad Sajid Anwar You are given a string containing only lower case English letters and digits. Write a script to remove all digits by removing the first digit and the closest non-digit character to its left. Example #1: Input: $str = "cab12" Output: "c" Round 1: remove "1" then "b" => "ca2" Round 2: remove "2" then "a" => "c" Example #2: Input: $str = "xy99" Output: "" Round 1: remove "9" then "y" => "x9" Round 2: remove "9" then "x" => "" Example #3: Input: $str = "pa1erl" Output: "perl"
I note that it will not be possible to remove "the character to the left of a digit" if the index of the digit is 0; so in that case, I'll just skip removing "character to left". In all other cases, I'll remove both each digit and the character to it's left. I'll use a 3-part index loop with double backtracking to avoid missing digits, and just keep erasing digits (and their left-hand men) until no digits remain.

Robbie Hatley's Perl Solution to The Weekly Challenge 330-1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 330-2: Title Capital Submitted by: Mohammad Sajid Anwar You are given a string made up of one or more words separated by a single space. Write a script to capitalize the given title. If the word length is 1 or 2 then convert the word to lowercase, otherwise make the first character uppercase and remaining lowercase. Example #1: Input: $str = "PERL IS gREAT" Output: "Perl is Great" Example #2: Input: $str = "THE weekly challenge" Output: "The Weekly Challenge" Example #3: Input: $str = "YoU ARE A stAR" Output: "You Are a Star"
I'll split the input on whitespace to an array, then I'll use a 3-part index loop to process each array element, Title-Casing each array element with size >=3 and lower-casing the remainder. Exception: This problem's description doesn't mention it, but the convention in English is to also Title-Case the first word of every title, so I'll also do that.

Robbie Hatley's Perl Solution to The Weekly Challenge 330-2
That's it for challenge 330; see you on challenge 331!
Comments
Post a Comment