aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-053/luca-ferrari/blog-1.txt1
-rw-r--r--challenge-053/luca-ferrari/blog-2.txt1
-rw-r--r--challenge-053/luca-ferrari/raku/ch-1.p669
-rw-r--r--challenge-053/luca-ferrari/raku/ch-2.p677
4 files changed, 148 insertions, 0 deletions
diff --git a/challenge-053/luca-ferrari/blog-1.txt b/challenge-053/luca-ferrari/blog-1.txt
new file mode 100644
index 0000000000..cae994db98
--- /dev/null
+++ b/challenge-053/luca-ferrari/blog-1.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2020/03/23/PerlWeeklyChallenge53.html#task1
diff --git a/challenge-053/luca-ferrari/blog-2.txt b/challenge-053/luca-ferrari/blog-2.txt
new file mode 100644
index 0000000000..72e20fe93f
--- /dev/null
+++ b/challenge-053/luca-ferrari/blog-2.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2020/03/23/PerlWeeklyChallenge53.html#task2
diff --git a/challenge-053/luca-ferrari/raku/ch-1.p6 b/challenge-053/luca-ferrari/raku/ch-1.p6
new file mode 100644
index 0000000000..1ee72eb589
--- /dev/null
+++ b/challenge-053/luca-ferrari/raku/ch-1.p6
@@ -0,0 +1,69 @@
+#!env raku
+#
+# Perl Weekly Challenge 53
+# <https://perlweeklychallenge.org/blog/perl-weekly-challenge-053/>
+#
+# Task 1
+#
+# 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 ]
+#
+#
+#
+# Example of invocation
+# % raku ch-1.p6 180
+# Rotation is 180
+# Original matrix is
+# | 1 | 2 | 3 |
+# | 4 | 5 | 6 |
+# | 7 | 8 | 9 |
+# Rotated matrix is
+# | 9 | 8 | 7 |
+# | 6 | 5 | 4 |
+# | 3 | 2 | 1 |
+#
+
+
+sub MAIN( Int:D $rotation where { $rotation == any( 90, 180, 270 ) } = 90 ) {
+
+ say "Rotation is $rotation";
+
+ my @matrix = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];
+ say "Original matrix is ";
+ say " | " ~ $_.join( " | " ) ~ " | " for @matrix;
+
+ my @rotated-matrix;
+
+ # do a loop for all the rotation
+ for 1 .. $rotation / 90 {
+
+ # the matrix is a square matrix, move on the columns
+ # to get the rotated row
+ for 0 .. @matrix.elems - 1 -> $current-column {
+ my @rotated-row;
+ for 0 .. @matrix.elems - 1 {
+ @rotated-row.push: @matrix[ @matrix.elems - 1 - $_ ][ $current-column ]
+ }
+
+ # push the rotated row to the new matrix
+ @rotated-matrix.push: [ @rotated-row ];
+ }
+
+ # switch the matrix, in the case we need to loop further
+ @matrix = @rotated-matrix;
+ @rotated-matrix = [];
+ }
+
+ say "Rotated matrix is ";
+ say " | " ~ $_.join( " | " ) ~ " | " for @matrix;
+
+}
diff --git a/challenge-053/luca-ferrari/raku/ch-2.p6 b/challenge-053/luca-ferrari/raku/ch-2.p6
new file mode 100644
index 0000000000..6bdc1bb388
--- /dev/null
+++ b/challenge-053/luca-ferrari/raku/ch-2.p6
@@ -0,0 +1,77 @@
+#!env raku
+#
+# Perl Weekly Challenge 53
+# <https://perlweeklychallenge.org/blog/perl-weekly-challenge-053/>
+#
+# Task 2
+#
+# 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
+#
+
+
+
+sub MAIN( Int:D $size where { 1 < $size <= 5 } = 2 ) {
+ say "Requested string length is $size ";
+ my @vowels = 'a', 'e', 'i', 'o', 'u';
+
+ # build a matrix with all the possibile combinations
+ my @combinations = @vowels;
+ for 1 ..^ $size {
+ @combinations = @combinations [X] @vowels;
+ }
+
+
+
+ for @combinations -> @letters {
+ my $string = @letters.join;
+ my $ok = True;
+
+ # test if all but the last letters do match the regular expression
+ loop ( my $i = 0; $i < @letters.elems - 1; $i++ ) {
+ my $letter = @letters[ $i ];
+ $ok = do
+ given $letter {
+ when 'a' { $string ~~ / a (e | i) / }
+ when 'e' { $string ~~ / ei / }
+ when 'i' { $string ~~ / i ( a | e | o | u ) / }
+ when 'o' { $string ~~ / o ( a | u ) / }
+ when 'u' { $string ~~ /u ( o | e ) / }
+ }.so;
+
+ # if not ok, do not continue
+ last if ! $ok;
+ }
+
+ say "Found { ~@letters }" if $ok;
+ }
+
+}