Task1
We decrypt the string according to the given rules, were single digits are handled differently from two-digit sequences:
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More tests => 5;
sub decrypt_string{
my %h;
my ($i,$c) = (1,'a');
$h{$i++} = $c++ foreach 1..9;
$h{$i++ . '#'} = $c++ foreach 10..26;
$_[0] =~ s/((?:1\d|2[0-6])#|\d)/$h{$1}/gr
}
is decrypt_string('10#11#12'),'jkab','Example 1';
is decrypt_string('1326#'),'acz','Example 2';
is decrypt_string('25#24#123'),'yxabc','Example 3';
is decrypt_string('20#5'),'te','Example 4';
is decrypt_string('1910#26#'),'aijz','Example 5';
Task2
We replace "()" with "o" and "(al)" with "al":
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More tests => 5;
sub goal_parser{
my %h = ('' => 'o',al => 'al');
$_[0] =~ s/\(((?:al)?)\)/$h{$1}/gr
}
is goal_parser('G()(al)'),'Goal','Example 1';
is goal_parser('G()()()()(al)'),'Gooooal','Example 2';
is goal_parser('(al)G(al)()()'),'alGaloo','Example 3';
is goal_parser('()G()G'),'oGoG','Example 4';
is goal_parser('(al)(al)G()()'),'alalGoo','Example 5';