aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCY Fung <fungcheokyin@gmail.com>2022-10-10 16:08:51 +0800
committerCY Fung <fungcheokyin@gmail.com>2022-10-10 16:08:51 +0800
commit55e952e2376a3e7817e2846d2fa089cdc38b8836 (patch)
tree32d5231c42d1a7f227cdfd444725ff9f22987254
parent30b5a6f49947856f98c056b00b2fe69404761593 (diff)
downloadperlweeklychallenge-club-55e952e2376a3e7817e2846d2fa089cdc38b8836.tar.gz
perlweeklychallenge-club-55e952e2376a3e7817e2846d2fa089cdc38b8836.tar.bz2
perlweeklychallenge-club-55e952e2376a3e7817e2846d2fa089cdc38b8836.zip
Week 186 Perl Solutions
-rw-r--r--challenge-186/cheok-yin-fung/perl/ch-1.pl20
-rw-r--r--challenge-186/cheok-yin-fung/perl/ch-2.pl20
2 files changed, 40 insertions, 0 deletions
diff --git a/challenge-186/cheok-yin-fung/perl/ch-1.pl b/challenge-186/cheok-yin-fung/perl/ch-1.pl
new file mode 100644
index 0000000000..27d1b4c16f
--- /dev/null
+++ b/challenge-186/cheok-yin-fung/perl/ch-1.pl
@@ -0,0 +1,20 @@
+use v5.30.0;
+use warnings;
+
+sub zip {
+ my @all = @_;
+ my $size = scalar @all / 2;
+ my @a = @_[0..$size-1];
+ my @b = @_[$size.. $#all];
+ # say @a; say @b;
+ my @ans;
+ ($ans[2*$_],$ans[2*$_+1]) = ($a[$_],$b[$_]) for 0..$size-1;
+ return @ans;
+}
+
+use Test::More tests=>2;
+use Test::Deep;
+my @a = qw/1 2 3/;
+my @b = qw/a b c/;
+cmp_deeply( [zip(@a, @b)], [qw/1 a 2 b 3 c/]);
+cmp_deeply( [zip(@b, @a)], [qw/a 1 b 2 c 3/]);
diff --git a/challenge-186/cheok-yin-fung/perl/ch-2.pl b/challenge-186/cheok-yin-fung/perl/ch-2.pl
new file mode 100644
index 0000000000..34bf7b847c
--- /dev/null
+++ b/challenge-186/cheok-yin-fung/perl/ch-2.pl
@@ -0,0 +1,20 @@
+use v5.30.0;
+use charnames ();
+use utf8;
+
+sub ch_latin {
+ my $name = charnames::viacode(ord($_[0]));
+ return $1 if $name =~ /^LATIN CAPITAL LETTER (\w)/;
+ return lc($1) if $name =~ /^LATIN SMALL LETTER (\w)/;
+ return $_[0];
+}
+
+sub makeover {
+ return join "", map {ch_latin $_} split "", $_[0]
+}
+
+use Test::More tests=>4;
+ok makeover("ÃÊÍÒÙ") eq "AEIOU";
+ok makeover("âÊíÒÙ") eq "aEiOU";
+ok makeover("chữ Quốc ngữ") eq "chu Quoc ngu";
+ok makeover("Paul Erdős") eq "Paul Erdos";