aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2022-04-13 11:25:04 +0100
committerPaulo Custodio <pauloscustodio@gmail.com>2022-04-13 11:25:04 +0100
commitfffef0a0521b04060898de864398ed258774a0c0 (patch)
treeb3d47ae7f0e06fb4d7b1c82cb328d3abc16a09da
parent49f7f459092f538b5468e255ff4e8ebac490d70a (diff)
downloadperlweeklychallenge-club-fffef0a0521b04060898de864398ed258774a0c0.tar.gz
perlweeklychallenge-club-fffef0a0521b04060898de864398ed258774a0c0.tar.bz2
perlweeklychallenge-club-fffef0a0521b04060898de864398ed258774a0c0.zip
Add Perl solution to challenge 053
-rw-r--r--challenge-053/paulo-custodio/Makefile2
-rw-r--r--challenge-053/paulo-custodio/README1
-rw-r--r--challenge-053/paulo-custodio/perl/ch-1.pl54
-rw-r--r--challenge-053/paulo-custodio/perl/ch-2.pl69
-rw-r--r--challenge-053/paulo-custodio/t/test-1.yaml17
-rw-r--r--challenge-053/paulo-custodio/t/test-2.yaml16
6 files changed, 159 insertions, 0 deletions
diff --git a/challenge-053/paulo-custodio/Makefile b/challenge-053/paulo-custodio/Makefile
new file mode 100644
index 0000000000..c3c762d746
--- /dev/null
+++ b/challenge-053/paulo-custodio/Makefile
@@ -0,0 +1,2 @@
+all:
+ perl ../../challenge-001/paulo-custodio/test.pl
diff --git a/challenge-053/paulo-custodio/README b/challenge-053/paulo-custodio/README
new file mode 100644
index 0000000000..87dc0b2fbd
--- /dev/null
+++ b/challenge-053/paulo-custodio/README
@@ -0,0 +1 @@
+Solution by Paulo Custodio
diff --git a/challenge-053/paulo-custodio/perl/ch-1.pl b/challenge-053/paulo-custodio/perl/ch-1.pl
new file mode 100644
index 0000000000..81f6eb8f96
--- /dev/null
+++ b/challenge-053/paulo-custodio/perl/ch-1.pl
@@ -0,0 +1,54 @@
+#!/usr/bin/env perl
+
+# Challenge 053
+#
+# TASK #1
+# Rotate Matrix
+# Write a script to rotate the followin matrix by given 90/180/270 degrees
+# clockwise.
+#
+# [ 1, 2, 3 ]
+# [ 4, 5, 6 ]
+# [ 7, 8, 9 ]
+# For example, if you rotate by 90 degrees then expected result should be like
+# below
+#
+# [ 7, 4, 1 ]
+# [ 8, 5, 2 ]
+# [ 9, 6, 3 ]
+
+use Modern::Perl;
+
+my @m = ([ 1, 2, 3 ],
+ [ 4, 5, 6 ],
+ [ 7, 8, 9 ]);
+
+display(rotate90(@m));
+display(rotate180(@m));
+display(rotate270(@m));
+
+
+sub rotate90 {
+ my(@m) = @_;
+ return ([ $m[2][0], $m[1][0], $m[0][0] ],
+ [ $m[2][1], $m[1][1], $m[0][1] ],
+ [ $m[2][2], $m[1][2], $m[0][2] ]);
+}
+
+sub rotate180 {
+ my(@m) = @_;
+ return rotate90(rotate90(@m));
+}
+
+sub rotate270 {
+ my(@m) = @_;
+ return rotate90(rotate90(rotate90(@m)));
+}
+
+sub display {
+ my(@m) = @_;
+ for (@m) {
+ say "[ ", join(", ", @$_), " ]"
+ }
+ say "";
+}
diff --git a/challenge-053/paulo-custodio/perl/ch-2.pl b/challenge-053/paulo-custodio/perl/ch-2.pl
new file mode 100644
index 0000000000..8eb54e16fa
--- /dev/null
+++ b/challenge-053/paulo-custodio/perl/ch-2.pl
@@ -0,0 +1,69 @@
+#!/usr/bin/env perl
+
+# Challenge 053
+#
+# TASK #2
+# Vowel Strings
+# Write a script to accept an integer 1 <= N <= 5 that would print all possible
+# strings of size N formed by using only vowels (a, e, i, o, u).
+#
+# The string should follow the following rules:
+#
+# ‘a’ can only be followed by ‘e’ and ‘i’.
+#
+# ‘e’ can only be followed by ‘i’.
+#
+# ‘i’ can only be followed by ‘a’, ‘e’, ‘o’, and ‘u’.
+#
+# ‘o’ can only be followed by ‘a’ and ‘u’.
+#
+# ‘u’ can only be followed by ‘o’ and ‘e’.
+#
+# For example, if the given integer N = 2 then script should print the following
+# strings:
+#
+# ae
+# ai
+# ei
+# ia
+# io
+# iu
+# ie
+# oa
+# ou
+# uo
+# ue
+
+use Modern::Perl;
+
+my $n = shift || 2;
+
+show_vowels($n, "");
+
+sub show_vowels {
+ my($n, $str) = @_;
+ if (length($str)==$n) {
+ say $str;
+ }
+ elsif ($str eq "") {
+ show_vowels($n, $str.$_) for (qw( a e i o u ));
+ }
+ elsif (substr($str, -1, 1) eq 'a') {
+ show_vowels($n, $str.$_) for (qw( e i ));
+ }
+ elsif (substr($str, -1, 1) eq 'e') {
+ show_vowels($n, $str.$_) for (qw( i ));
+ }
+ elsif (substr($str, -1, 1) eq 'i') {
+ show_vowels($n, $str.$_) for (qw( a e o u ));
+ }
+ elsif (substr($str, -1, 1) eq 'o') {
+ show_vowels($n, $str.$_) for (qw( a u ));
+ }
+ elsif (substr($str, -1, 1) eq 'u') {
+ show_vowels($n, $str.$_) for (qw( e o ));
+ }
+ else {
+ die;
+ }
+}
diff --git a/challenge-053/paulo-custodio/t/test-1.yaml b/challenge-053/paulo-custodio/t/test-1.yaml
new file mode 100644
index 0000000000..7026d4ac62
--- /dev/null
+++ b/challenge-053/paulo-custodio/t/test-1.yaml
@@ -0,0 +1,17 @@
+- setup:
+ cleanup:
+ args:
+ input:
+ output: |
+ |[ 7, 4, 1 ]
+ |[ 8, 5, 2 ]
+ |[ 9, 6, 3 ]
+ |
+ |[ 9, 8, 7 ]
+ |[ 6, 5, 4 ]
+ |[ 3, 2, 1 ]
+ |
+ |[ 3, 6, 9 ]
+ |[ 2, 5, 8 ]
+ |[ 1, 4, 7 ]
+ |
diff --git a/challenge-053/paulo-custodio/t/test-2.yaml b/challenge-053/paulo-custodio/t/test-2.yaml
new file mode 100644
index 0000000000..b69358fcba
--- /dev/null
+++ b/challenge-053/paulo-custodio/t/test-2.yaml
@@ -0,0 +1,16 @@
+- setup:
+ cleanup:
+ args: 2
+ input:
+ output: |
+ |ae
+ |ai
+ |ei
+ |ia
+ |ie
+ |io
+ |iu
+ |oa
+ |ou
+ |ue
+ |uo