aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-03-25 13:15:18 +0000
committerGitHub <noreply@github.com>2020-03-25 13:15:18 +0000
commitbe05879aab0d6383a0e91c2b003eb81297e3d9cb (patch)
tree372fff632ff0ff9c7c2e5f6ccb19b8965bba7840
parentec0b347851a9837e9b724af780980e445a05034f (diff)
parent03c11ab826fad9467819f05b6f138d27acdd8382 (diff)
downloadperlweeklychallenge-club-be05879aab0d6383a0e91c2b003eb81297e3d9cb.tar.gz
perlweeklychallenge-club-be05879aab0d6383a0e91c2b003eb81297e3d9cb.tar.bz2
perlweeklychallenge-club-be05879aab0d6383a0e91c2b003eb81297e3d9cb.zip
Merge pull request #1460 from choroba/ech053
Add solutions to 053 (Rotate Matrix + Vowel String) by E. Choroba
-rwxr-xr-xchallenge-053/e-choroba/perl/ch-1.pl16
-rwxr-xr-xchallenge-053/e-choroba/perl/ch-2.pl26
2 files changed, 42 insertions, 0 deletions
diff --git a/challenge-053/e-choroba/perl/ch-1.pl b/challenge-053/e-choroba/perl/ch-1.pl
new file mode 100755
index 0000000000..d71ca95244
--- /dev/null
+++ b/challenge-053/e-choroba/perl/ch-1.pl
@@ -0,0 +1,16 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+
+use PDL;
+
+my $matrix = pdl([1, 2, 3],
+ [4, 5, 6],
+ [7, 8, 9]);
+
+for my $rotation (0, 90, 180, 270) {
+ my $times = $rotation / 90;
+ my $result = $matrix;
+ $result = $result->transpose->slice([-1, 0]) for 1 .. $times;
+ print "$rotation:$result";
+}
diff --git a/challenge-053/e-choroba/perl/ch-2.pl b/challenge-053/e-choroba/perl/ch-2.pl
new file mode 100755
index 0000000000..719f58ddcc
--- /dev/null
+++ b/challenge-053/e-choroba/perl/ch-2.pl
@@ -0,0 +1,26 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use feature qw{ say };
+
+my %next = (
+ a => [qw[ e i ]],
+ e => [qw[ i ]],
+ i => [qw[ a e o u ]],
+ o => [qw[ a u ]],
+ u => [qw[ o e ]]);
+
+my $n = shift;
+die "Invalid argument" unless ($n // "") =~ /^[1-5]$/;
+
+my @agenda = sort keys %next;
+
+while ($n > length $agenda[0]) {
+ my @next;
+ for my $string (@agenda) {
+ my $last = substr $string, -1;
+ push @next, map $string . $_, @{ $next{$last} };
+ }
+ @agenda = @next;
+}
+say for @agenda;