aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCY Fung <fungcheokyin@gmail.com>2023-04-16 23:25:25 +0800
committerCY Fung <fungcheokyin@gmail.com>2023-04-16 23:25:25 +0800
commit67c36d093dc4dd1ca60b9fad045d892b8097a0dd (patch)
tree8c31b929862604a45863bd26f6387d37e18d931a
parent772da8b836eafc8391e3e1cff0416465a5877a01 (diff)
downloadperlweeklychallenge-club-67c36d093dc4dd1ca60b9fad045d892b8097a0dd.tar.gz
perlweeklychallenge-club-67c36d093dc4dd1ca60b9fad045d892b8097a0dd.tar.bz2
perlweeklychallenge-club-67c36d093dc4dd1ca60b9fad045d892b8097a0dd.zip
Week 212 Task 1
-rw-r--r--challenge-212/cheok-yin-fung/perl/ch-1.pl25
1 files changed, 25 insertions, 0 deletions
diff --git a/challenge-212/cheok-yin-fung/perl/ch-1.pl b/challenge-212/cheok-yin-fung/perl/ch-1.pl
new file mode 100644
index 0000000000..53f15f116a
--- /dev/null
+++ b/challenge-212/cheok-yin-fung/perl/ch-1.pl
@@ -0,0 +1,25 @@
+# The Weekly Challenge 212
+# Task 1 Jumping Letters
+use v5.30.0;
+use warnings;
+use List::Util qw/zip/;
+
+sub map_letter {
+ my $char = $_[0];
+ my $dist = $_[1];
+ return chr( ord('A') + (ord($char)-ord('A')+$dist) % 26 )
+ if $char =~ m/[A-Z]/;
+ return chr( ord('a') + (ord($char)-ord('a')+$dist) % 26 )
+ if $char =~ m/[a-z]/;
+}
+
+sub jl {
+ my $word = $_[0];
+ my @jump = $_[1]->@*;
+ die "length not match" unless length $word == scalar @jump;
+ return join "", map {map_letter $_->@*} zip [split "", $word], [@jump];
+}
+
+use Test::More tests=>2;
+ok jl("Perl", [2,22,19,9]) eq "Raku";
+ok jl("Raku", [24,4,7,17]) eq "Perl";