Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #402 (“Letters Only Hex” and “Circular String Rotations”)
For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two tasks, with a new pair of tasks each Monday. You can find it here: The Weekly Challenge
The Weekly Challenge for the week of 2026-11-30 through 2026-12-06 is #402. The tasks for this challenge are as follows:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 402-1: Letters Only Hex Submitted by: Mohammad Sajid Anwar You are given a string representing a decimal integer >= 1 without leading zeros. Write a script that to convert the given string into its uppercase hexadecimal representation. Replace every digit ‘0’ with the letter ‘O’, also replace every digit ‘1’ with the letter ‘I’. The resulting string should only contain characters: ‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’, ‘I’, and ‘O’.
To solve this problem, I'll use the excellent base-conversion routines in CPAN module "Math::BigInt" to make the hex version, use "y" to transliterate all "01" to "OI", then check to see if the result matches "/^[ABCDEFOI]+$/". If it does, return the result; else, return ''.
Robbie Hatley's Perl Solution to The Weekly Challenge 402-1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 402-2: Circular String Rotations Submitted by: Mohammad Sajid Anwar You are given a string containing lowercase English letters and directions array in the form [direction, amount]. The direction 0 is left shift and direction 1 is right shift. Write a script to apply the sequence of left and right rotations to the given string and return the final string.
To solve this problem, I first check the input for validity, then perform the required rotations, then return the result.
Robbie Hatley's Perl Solution to The Weekly Challenge 402-2
That's it for challenge 402; see you on challenge 403!
Comments
Post a Comment