Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #364 (“Decrypt String” and “Goal Parser”)

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-09 through 2026-03-15 is #364. The tasks for challenge #364 are as follows:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Task 364-1: Decrypt String
Submitted by: Mohammad Sajid Anwar
You are given a string formed by digits and ‘#'. Write a script
to map the given string to English lowercase characters given
the following two rules:
1: Characters 'j' to 'z' are represented by '10#' to '26#'.
2: Characters 'a' to 'i' are represented by '1' to '9'.

Example #1:
Input: $str = "10#11#12"
Output: "jkab"

Example #2:
Input: $str = "1326#"
Output: "acz"

Example #3:
Input: $str = "25#24#123"
Output: "yxabc"

Example #4:
Input: $str = "20#5"
Output: "te"

Example #5:
Input: $str = "1910#26#"
Output: "aijz"

Perl’s "s///" operator, in "evaluate globally" mode ("/eg"), will make easy work of this.

Robbie Hatley's Perl Solution to The Weekly Challenge 364-1

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Task 364-2: Goal Parser
Submitted by: Mohammad Sajid Anwar
You are given a string, $str. Write a script to interpret the
given string using Goal Parser. The Goal Parser interprets “G” as
the string “G”, “()” as the string “o”, and “(al)” as the string
“al”. The interpreted strings are then concatenated in the
original order.

Example #1:
Input: $str = "G()(al)"
Output: "Goal"

Example #2:
Input: $str = "G()()()()(al)"
Output: "Gooooal"

Example #3:
Input: $str = "(al)G(al)()()"
Output: "alGaloo"

Example #4:
Input: $str = "()G()G"
Output: "oGoG"

Example #5:
Input: $str = "(al)(al)G()()"
Output: "alalGoo"

s/\(\))/o/g; s/\(al\)/al/g;

Robbie Hatley's Perl Solution to The Weekly Challenge 364-2

That's it for challenge 364; see you on challenge 365!

Comments

Popular posts from this blog

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #334 (“Range Sum” and “Nearest Valid Point”)

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #336 (“Equal Group” and “Final Score”)

Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #326 (“Day of Year” and “Decompressed List”)