Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #362 (“Echo Chamber” and “Spellbound Sorting”)
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-02-23 through 2026-03-01 is #362. The tasks for challenge #362 are as follows:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 362-1: Echo Chamber Submitted by: Mohammad Sajid Anwar You are given a string containing lowercase letters. Write a script to transform the string based on the index position of each character (starting from 0). For each character at position i, repeat it i + 1 times. Example #1: Input: "abca" Output: "abbcccaaaa" Example #2: Input: "xyz" Output: "xyyzzz" Example #3: Input: "code" Output: "coodddeeee" Example #4: Input: "hello" Output: "heelllllllooooo" Example #5: Input: "a" Output: "a"
This is just a matter of doing exactly as the problem description says. I use the "x" operator to make multiple copies of letters.
Robbie Hatley's Perl Solution to The Weekly Challenge 362-1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 362-2: Spellbound Sorting Submitted by: Peter Campbell Smith You are given an array of integers. Write a script to return them in alphabetical order, in any language of your choosing. Default language is English. Example #1: Input: (6, 7, 8, 9 ,10) Output: (8, 9, 7, 6, 10) eight, nine, seven, six, ten Example #2: Input: (-3, 0, 1000, 99) Output: (-3, 99, 1000, 0) minus three, ninety-nine, one thousand, zero Example #3: Input: (1, 2, 3, 4, 5) Output: (5, 2, 4, 3, 1) for French language cinq, deux, quatre, trois, un Output: (5, 4, 1, 3, 2) for English language five, four, one, three, two Example #4: Input: (0, -1, -2, -3, -4) Output: (-4, -1, -3, -2, 0) minus four, minus one, minus three, minus two, zero Example #5: Input: (100, 101, 102) Output: (100, 101, 102) one hundred, one hundred and one, one hundred and two
Fortunately, I already wrote a "number to words" script long ago. It's in English only, because that's the only language I know the number words for. It's too complicated for me to describe exactly how it works here, but I'll say this much: it involves "Math::BigFloat", "Math::BigInt", place values, and a look-up table for place-value groups from "thousand" through "duotrigintillion". If you want the exact details, you'll have to read the script.
Robbie Hatley's Perl Solution to The Weekly Challenge 362-2
That's it for challenge 362; see you on challenge 363!
Comments
Post a Comment