Posts

Showing posts from March, 2025

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #315 (Theme: “If I Had Words”)

Image
For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two parts, cycling every Sunday. You can find it here: The Weekly Challenge The Weekly Challenge for the week of 2025-03-31 through 2025-04-06 is #315. “If I had words To make a day for you I sing you a morning golden and new “I would make this day Last for all time Give you a night Deep in moonshine” ~~Johnathan Hodge The tasks for challenge #315 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 315-1: Find Words Submitted by: Mohammad Sajid Anwar You are given a list of words and a character. Write a script to return the index of word in the list where you find the given character. Example #1: Input: @list = ("the", "weekly", "challenge") $char = "e" Output: (0, 1, 2) Example #2: Input: @list = ("perl", "raku", "python") $char = "p" ...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #314 (Theme: "Destroy Unwanted Columns")

Image
For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two parts, cycling every Sunday. You can find it here: The Weekly Challenge The Weekly Challenge for the week of 2025-03-24 through 2025-03-30 is #314. The tasks for challenge #314 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 314-1: Equal Strings Submitted by: Mohammad Sajid Anwar You are given three strings. You are allowed to remove the rightmost character of a string to make all equals. Write a script to return the number of operations to make it equal, otherwise -1. Example #1: Input: $s1 = "abc", $s2 = "abb", $s3 = "ab" Output: 2 Operation 1: Delete "c" from the string "abc" Operation 2: Delete "b" from the string "abb" Example #2: Input: $s1 = "ayz", $s2 = "cyz", $s3 = "xyz" Output: -1 Example #3: Input: $s1 = "yza", $s...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #313 ("Broken Keys" and "Reverse Letters")

Image
For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two parts, cycling every Sunday. You can find it here: The Weekly Challenge The Weekly Challenge for the week of 2025-03-17 through 2025-03-23 is #313. The tasks for challenge #313 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 313-1: Broken Keys Submitted by: Mohammad Sajid Anwar You have a broken keyboard which sometimes type a character more than once. You are given a string and actual typed string. Write a script to find out if the actual typed string is meant for the given string. Example #1: Input: $name = "perl", $typed = "perrrl" Output: true Here "r" is pressed 3 times instead of 1 time. Example #2: Input: $name = "raku", $typed = "rrakuuuu" Output: true Example #3: Input: $name = "python", $typed = "perl" Output: false Example #4: Input: $name = "coff...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #312 ("Minimum Time" and "Balls and Boxes")

Image
For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two parts, cycling every Sunday. You can find it here: The Weekly Challenge The Weekly Challenge for the week of 2025-03-10 through 2025-03-16 is #312. The tasks for challenge #312 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 312-1: Minimum Time Submitted by: Mohammad Sajid Anwar You are given a typewriter with lowercase english letters a to z arranged in a circle. Typing a character takes 1 second. Moving the pointer one character clockwise or anti-clockwise also takes 1 second. The pointer initially points to a. Write a script to return minimum time it takes to print a given string. Example #1: Input: $str = "abc" Output: 5 The pointer is at 'a' initially. 1 sec - type the letter 'a' 1 sec - move pointer clockwise to 'b' 1 sec - type the letter 'b' 1 sec - move pointer clockwise to 'c...

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #311 ("Upper Lower" and "Group Digit Sum")

Image
For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two parts, cycling every Sunday. You can find it here: The Weekly Challenge The Weekly Challenge for the week of 2025-03-03 through 2025-03-09 is #311. The tasks for challenge #311 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 311-1: Upper Lower Submitted by: Mohammad Sajid Anwar You are given a string consisting of english letters only. Write a script to convert lower case to upper and upper case to lower in the given string. Example #1: Input: $str = "pERl" Output: "PerL" Example #2: Input: $str = "rakU" Output: "RAKu" Example #3: Input: $str = "PyThOn" Output: "pYtHoN" This can be easily done with a one-liner using Perl's "transpose" operator, "tr", aka "y": y/[a-zA-Z]/[A-Za-z]/,print while <> Robbie Hatley's Pe...