From 03c11ab826fad9467819f05b6f138d27acdd8382 Mon Sep 17 00:00:00 2001 From: "E. Choroba" Date: Tue, 24 Mar 2020 01:11:17 +0100 Subject: Add solutions to 053 (Rotate Matrix + Vowel String) by E. Choroba --- challenge-053/e-choroba/perl/ch-1.pl | 16 ++++++++++++++++ challenge-053/e-choroba/perl/ch-2.pl | 26 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100755 challenge-053/e-choroba/perl/ch-1.pl create mode 100755 challenge-053/e-choroba/perl/ch-2.pl 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; -- cgit