aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYsmael Ebreo <Ysmael.Ebreo@latticesemi.com>2020-03-23 14:31:10 +0800
committerYsmael Ebreo <Ysmael.Ebreo@latticesemi.com>2020-03-23 14:31:10 +0800
commitb7df223b5553fed99664ec4f80448b2f408eb131 (patch)
tree728e4424bd114a121e4e9c34ab8048184307cc03
parent518733e4b9137d3fb6ca167b22e390d12853d7c4 (diff)
downloadperlweeklychallenge-club-b7df223b5553fed99664ec4f80448b2f408eb131.tar.gz
perlweeklychallenge-club-b7df223b5553fed99664ec4f80448b2f408eb131.tar.bz2
perlweeklychallenge-club-b7df223b5553fed99664ec4f80448b2f408eb131.zip
Added perl ch#53-1 solution
-rw-r--r--challenge-053/yet-ebreo/perl/ch-1.pl45
1 files changed, 45 insertions, 0 deletions
diff --git a/challenge-053/yet-ebreo/perl/ch-1.pl b/challenge-053/yet-ebreo/perl/ch-1.pl
new file mode 100644
index 0000000000..acc3cc4049
--- /dev/null
+++ b/challenge-053/yet-ebreo/perl/ch-1.pl
@@ -0,0 +1,45 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use feature 'say';
+# 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 ]
+
+my @matrix = (
+ [ 1, 2, 3 ],
+ [ 4, 5, 6 ],
+ [ 7, 8, 9 ],
+);
+
+#Obfuscated routine to rotate array 90cw, because it's perl. :D
+sub rotate {@{$_[0]}=map[map$_[0]->[-$_][$'],//..@{$_[0]}],0..~-@{$_[0]->[0]}}
+rotate (\@matrix) for 1..($ARGV[0]||90)/90 % 4;
+map {say "@{$_}"} @matrix;
+=begin
+perl .\ch-1.pl 90
+7 4 1
+8 5 2
+9 6 3
+
+perl .\ch-1.pl 180
+9 8 7
+6 5 4
+3 2 1
+
+perl .\ch-1.pl 270
+3 6 9
+2 5 8
+1 4 7
+
+perl .\ch-1.pl 360
+1 2 3
+4 5 6
+7 8 9
+=cut \ No newline at end of file