Posts

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #363 (“String Lie Detector” and “Subnet Sheriff”)

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-03-02 through 2026-03-08 is #363. The tasks for challenge #363 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 363-1: String Lie Detector Submitted by: Mohammad Sajid Anwar You are given a string. Write a script that parses a self-referential string and determines whether its claims about itself are true. The string will make statements about its own composition, specifically the number of vowels and consonants it contains. ( # Example #1 input: "aa — two vowels and zero consonants", # Expected output: true # Example #2 input: "iv — one vowel and one consonant", # Expected output: true # Example #3 input: "hello - three vowels and two consonants", # Exp...

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

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #358 (“Max Str Value” and “Encrypted String”)

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-01-26 through 2026-02-01 is #358. The tasks for challenge #358 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 358-1: Max Str Value Submitted by: Mohammad Sajid Anwar You are given an array of alphanumeric string, @strings. Write a script to find the max "value" of alphanumeric string in the given array which is the numeric representation of the string if it consists of digits only, otherwise the length of the string. Example #1: Input: @strings = ("123", "45", "6") Output: 123 "123" -> 123 "45" -> 45 "6" -> 6 Example #2: Input: @strings = ("abc", "de", "fghi") Output: 4 "abc" -> 3 ...

Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #357 (“Kaprekar Constant” and “Unique Fraction Generator”)

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-01-19 through 2026-01-25 is #357. The tasks for challenge #357 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 357-1: Kaprekar Constant Submitted by: Mohammad Sajid Anwar Write a function that takes a 4-digit integer and returns how many iterations of the following algorithm are required to reach Kaprekar’s constant (6174). (For more information about Kaprekar's Constant, see "https://en.wikipedia.org/wiki/6174".) 1. Select any four-digit number that has at least two different digits (leading zeros are allowed). 2. Create two new four-digit numbers by arranging the original digits in a.) ascending and b.) descending order (adding leading zeros if necessary). 3. Subtract...