aboutsummaryrefslogtreecommitdiff
path: root/challenge-053
diff options
context:
space:
mode:
authorFung Cheok Yin <61836418+E7-87-83@users.noreply.github.com>2020-03-29 14:34:10 +0800
committerGitHub <noreply@github.com>2020-03-29 14:34:10 +0800
commitceb7ce7b1aac09b72efda46352f9a2b6e5757ca1 (patch)
treec5ca6e3c1a5590c00d379ceac4442841c587f53d /challenge-053
parentde36304d152a06501b2c79667da704789efa66dd (diff)
downloadperlweeklychallenge-club-ceb7ce7b1aac09b72efda46352f9a2b6e5757ca1.tar.gz
perlweeklychallenge-club-ceb7ce7b1aac09b72efda46352f9a2b6e5757ca1.tar.bz2
perlweeklychallenge-club-ceb7ce7b1aac09b72efda46352f9a2b6e5757ca1.zip
Rename ch-1.pl to challenge-053/cheok-yin-fung/perl/ch-1.pl
Diffstat (limited to 'challenge-053')
-rw-r--r--challenge-053/cheok-yin-fung/perl/ch-1.pl55
1 files changed, 55 insertions, 0 deletions
diff --git a/challenge-053/cheok-yin-fung/perl/ch-1.pl b/challenge-053/cheok-yin-fung/perl/ch-1.pl
new file mode 100644
index 0000000000..10743d413e
--- /dev/null
+++ b/challenge-053/cheok-yin-fung/perl/ch-1.pl
@@ -0,0 +1,55 @@
+#!/usr/bin/perl
+use strict;
+
+# Perl Weekly Challenge #053 Task #1
+# Usage : ch-1.pl [the ANGLE, 90's multiples] 1 2 3 4 5 6 7 8 9
+# Example Input : ch-1.pl 90 1 2 3 4 5 6 7 8 9
+# Example Output:
+# 7 4 1
+# 8 5 2
+# 9 6 3
+
+my $ANGLE = shift @ARGV;
+
+my @cp = ( #short for coordinateplane
+ 3, 2, 1,
+ 4, -1, 0,
+ 5, 6, 7);
+# contrast with the natural array 3x3->9
+# 0 1 2
+# 3 4 5
+# 6 7 8
+
+my %hash;
+foreach (1..9) {
+ if ($_>=0) {$hash{$cp[$_-1]} = $ARGV[$_-1];}
+}
+$hash{-1} = @ARGV[4];
+
+
+sub rcaqx { #short for Rotation_Clockwise_A_Quarter, x for multiple
+ if ($_[0]>=1) {
+ my %nhash;
+ for (0..8) {
+ if ( $cp[$_] >= 0 ) {
+ $nhash{ $cp[$_] } = $hash{ ($cp[($_ )]+2) % 8 };
+ }
+ }
+ $nhash{-1} = $hash{-1};
+ %hash = %nhash;
+ rcaqx($_[0]-1);
+ }
+}
+
+rcaqx($ANGLE/90);
+
+
+for (0..8) {
+ print "\n" if $_ % 3 == 0;
+ if ($cp[$_] != -1) {
+ print $hash{$cp[$_]}, " ";
+ } else {
+ print $hash{-1}," ";
+ }
+}
+