Posts

Showing posts from February, 2026

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #362 (“Echo Chamber” and “Spellbound Sorting”)

Image
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 ju...

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #361 (“Zeckendorf Representation” and “Find Celebrity”)

Image
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-16 through 2026-02-22 is #361. The tasks for challenge #361 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 361-1: Zeckendorf Representation Submitted by: Mohammad Sajid Anwar You are given a positive integer (<= 100). Write a script to return Zeckendorf Representation of the given integer. Every positive integer can be uniquely represented as sum of non-consecutive Fibonacci numbers. Example 1 Input: $int = 4 Output: 3,1 4 => 3 + 1 (non-consecutive Fibonacci numbers) Example 2 Input: $int = 12 Output: 8,3,1 12 => 8 + 3 + 1 Example 3 Input: $int = 20 Output: 13,5,2 20 => 13 + 5 + 2 Example 4 Input: $int = 96 Output: 89,5,2 96 => 89 + 5 + 2 Example 5 Input: $int = 100 Output: 89,8,3 100 =...

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #360 (“Text Justifier” and “Word Sorter”)

Image
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-09 through 2026-02-15 is #360. The tasks for challenge #360 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 360-1: Text Justifier Submitted by: Mohammad Sajid Anwar You are given a string and a width. Write a script to return the string that centers the text within that width using asterisks * as padding. ( # Example #1 input: ["Hi", 5], # Expected output: "*Hi**" # Example #2 input: ["Code", 10], # Expected output: "***Code***" # Example #3 input: ["Hello", 9], # Expected output: "**Hello**" # Example #4 input: ["Perl", 4], # Expected output: "Perl" # Example #5 input: ["A"...

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #359 (“Digital Root” and “String Reduction”)

Image
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-02 through 2026-02-08 is #359. The tasks for challenge #359 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 359-1: Digital Root Submitted by: Mohammad Sajid Anwar You are given a positive integer, $int. Write a function that calculates the additive persistence of a positive integer and also return the digital root. Digital root is the recursive sum of all digits in a number until a single digit is obtained. Additive persistence is the number of times you need to sum the digits to reach a single digit. Example #1: Input: $int = 38 Expected output: Digital Root = 2; Persistence = 2 Example #2: Input: $int = 7 Expected output: Digital Root = 7; Persistence = 0 Example #3: Input: $int = 999 Expected output: Di...