Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #392 (“Convert Palindrome” and “Words Length Product”)
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-09-21 through 2026-09-27 is #392.
The tasks for challenge #392 are as follows:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 392-1: Convert Palindrome Submitted by: Mohammad Sajid Anwar Write a script to convert a given string to a palindrome by concatenating the minimum number of characters to its left.
To solve this problem, I realized that to minimize letters added, I should look for the longest palindromic prefix within the word, then just tack the reversed remainder to the word's left.
Robbie Hatley's Perl Solution to The Weekly Challenge 392-1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 392-2: Words Length Product Submitted by: Mohammad Sajid Anwar You are given an array of strings. Write a script to return the maximum value of len($words[i])*len($words[j]) where the two words do not share common letters. If no such two words exist,return 0.
To solve this problem, I use a m// matching operator inside a pair of nested 3-part loops to compare each possible pair of words; for each pair which has no letters in-common, if the product of their lengths is greater than maximum, I set maximum to product.
Robbie Hatley's Perl Solution to The Weekly Challenge 392-2
That's it for challenge 392; see you on challenge 393!
Comments
Post a Comment