aboutsummaryrefslogtreecommitdiff
path: root/challenge-186
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-186')
-rwxr-xr-xchallenge-186/colin-crain/perl/ch-1.pl71
-rwxr-xr-xchallenge-186/colin-crain/perl/ch-2.pl94
2 files changed, 165 insertions, 0 deletions
diff --git a/challenge-186/colin-crain/perl/ch-1.pl b/challenge-186/colin-crain/perl/ch-1.pl
new file mode 100755
index 0000000000..2a13991796
--- /dev/null
+++ b/challenge-186/colin-crain/perl/ch-1.pl
@@ -0,0 +1,71 @@
+#!/Users/colincrain/perl5/perlbrew/perls/perl-5.32.0/bin/perl
+#
+# .pl
+#
+# Zip List
+# Submitted by: Mohammad S Anwar
+# You are given two list @a and @b of same size.
+#
+# Create a subroutine sub zip(@a, @b) that merge the two list as
+# shown in the example below.
+#
+# Example
+#
+# Input: @a = qw/1 2 3/; @b = qw/a b c/;
+# Output: zip(@a, @b) should return qw/1 a 2 b 3 c/;
+# zip(@b, @a) should return qw/a 1 b 2 c 3/;
+#
+# method
+# I've never much been a fan of Perl function prototypes. They
+# always seemed a half-measure, emphasising what they were not,
+# which is is proper subroutine signature. They added a minor
+# hassle with little practical benefit, for me at least. And
+# others too, apparently, as they never much caught on.
+
+# When actual subroutine signatures were introduced things got a
+# little wierder, as protptypes and signatures occupy the same
+# semantic positioning. This is obviated by the :prototype keyword,
+# which must now be used should two need to coexist. Personally I
+# find this more pleasing, as it very much labels the prototypes as
+# *not* being a signature, which I always brought down the
+# readability of code using them. They're still esoteric, but at
+# least less outright confusingly.
+
+# All this is to satisfy Mohammads request that we provide a zip
+# subroutine that is fed two arrays, and not array references.
+# Sneaky twist that, but we deliver noethelass.
+#
+# © 2022 colin crain
+## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
+
+
+
+use warnings;
+use strict;
+use utf8;
+use feature ":5.26";
+use feature qw(signatures);
+no warnings 'experimental::signatures';
+
+
+sub zip :prototype(\@@);
+
+my @a = (1,2,3);
+my @b = (4,5,6);
+
+my @res = zip @a, @b;
+say "@res";
+
+
+sub zip :prototype(\@@) ($one, @two) {
+ my @out;
+ for ($one->@*) {
+ push @out, $_, shift @two;
+ }
+ return @out;
+}
+
+
+
+
+
diff --git a/challenge-186/colin-crain/perl/ch-2.pl b/challenge-186/colin-crain/perl/ch-2.pl
new file mode 100755
index 0000000000..a7b14ec29d
--- /dev/null
+++ b/challenge-186/colin-crain/perl/ch-2.pl
@@ -0,0 +1,94 @@
+#!/Users/colincrain/perl5/perlbrew/perls/perl-5.32.0/bin/perl
+#
+# uni-no-local.pl
+
+# Unicode Makeover
+# Submitted by: Mohammad S Anwar
+# You are given a string with possible unicode characters.
+#
+# Create a subroutine sub makeover($str) that replace the unicode
+# characters with ascii equivalent. For this task, let us assume it
+# only contains alphabets.
+#
+# Example 1
+# Input: $str = 'ÃÊÍÒÙ'
+# Output: 'AEIOU'
+#
+# Example 2
+# Input: $str = 'âÊíÒÙ'
+# Output: 'aEiOU'
+#
+# method:
+#
+# Let's being by saying this job, the big, job, the _real_ job, is
+# non-trivial. It's not exactly clear what a unicode character with
+# an ascii equivalent means. There are, for instance, characters
+# like the Icelandic Thorn, which map very cleanly to the English
+# ASCII characters TH. This isn't an approximation either, as the
+# glyph was orignally part of the English alphabet to designate
+# that exact sound.
+#
+#
+# © 2022 colin crain
+## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
+
+
+
+use warnings;
+use strict;
+use utf8;
+use feature ":5.26";
+use feature qw(signatures);
+no warnings 'experimental::signatures';
+use open ":std", ":encoding(UTF-8)";
+use charnames ':full';
+
+use Text::Unidecode;
+
+my $str = 'âÊíÒÙ';
+my $let = $str;
+
+say "input: ", $str;
+
+say "unidecode: ", unidecode( $str );
+say "makeover: ", makeover($str);
+
+sub makeover ($str) {
+ my @in = split //, $str;
+ my $out;
+ for (@in) {
+ $out .= uni2ascii($_);
+ }
+ return $out;
+
+
+}
+
+sub uni2ascii ( $char ) {
+ my $let = $char;
+ my $hex = sprintf '%x', ord $char;
+ my $name = charnames::viacode("0x$hex");
+
+ my $qualifier = '(?:AFRICAN |REVERSED |TURNED )';
+ return '' if $name =~ /^COMBINING/; ## strip combining characters
+
+ if ($name =~ /LATIN (CAPITAL|SMALL) LETTER ([A-Z])(?:\s|\n|$)/) {
+ $let = $1 eq 'SMALL'
+ ? lc($2)
+ : $2 ;
+ }
+
+ return $let;
+
+}
+
+
+
+use Test::More;
+
+is makeover( 'ÃÊÍÒÙ' ), 'AEIOU', 'ex-1';
+is makeover( 'âÊíÒÙ' ), 'aEiOU', 'ex-2';
+is makeover( 'resumé' ), 'resume', 'mixed ascii + unicode';
+is makeover( 'Ģ' ), 'G', 'LATIN CAPITAL LETTER G WITH CEDILLA';
+
+done_testing();