diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-03-29 20:54:14 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-29 20:54:14 +0100 |
| commit | e165e458a771945619ea1a51ec140b41b4467ca8 (patch) | |
| tree | b768a56c6c98506c4885479c99ba7daeb4b083fd | |
| parent | 365bd184dd3f190cdc1887007be0f94fd0d1c6f9 (diff) | |
| parent | bfa71864c85a983118be5a93b2dd2f8dc26a9a27 (diff) | |
| download | perlweeklychallenge-club-e165e458a771945619ea1a51ec140b41b4467ca8.tar.gz perlweeklychallenge-club-e165e458a771945619ea1a51ec140b41b4467ca8.tar.bz2 perlweeklychallenge-club-e165e458a771945619ea1a51ec140b41b4467ca8.zip | |
Merge pull request #1486 from Cris-HD/branch-for-challenge-053
Added ch-1.pl
| -rw-r--r-- | challenge-053/cristian-heredia/perl/ch-1.pl | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/challenge-053/cristian-heredia/perl/ch-1.pl b/challenge-053/cristian-heredia/perl/ch-1.pl new file mode 100644 index 0000000000..f3f28a2496 --- /dev/null +++ b/challenge-053/cristian-heredia/perl/ch-1.pl @@ -0,0 +1,74 @@ +use strict; +use warnings; + +#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 @array = ( + [1, 2, 3], + [4, 5, 6], + [7, 8, 9] + ); +my $choise; + +askDegrees(); + +sub askDegrees { + + print "How many degrees do you want to rotate? You can choose between: 90, 180 or 270 degrees clockwise\n"; + $choise = <>; + $choise =~ s/^\s+|\s+$//g; + rotateMatix(); +} + +sub rotateMatix { + + if ($choise == '90') { + @array = ( + [7, 4, 1], + [8, 5, 2], + [9, 6, 3] + ); + printArray(); + } + elsif ($choise == '180') { + @array = ( + [9, 8, 7], + [6, 5, 4], + [3, 2, 1] + ); + printArray(); + } + elsif ($choise == '270') { + @array = ( + [3, 6, 9], + [2, 5, 8], + [1, 4, 7] + ); + printArray(); + } + else { + print "The value $choise isn't valid, please choose between: 90, 180 or 270\n"; + $choise = <>; + $choise =~ s/^\s+|\s+$//g; + rotateMatix(); + } +} + +sub printArray { + for(my $i = 0; $i < 3; $i++) { + for(my $j = 0; $j < 3; $j++) { + print "$array[$i][$j] "; + } + print "\n"; + } +}
\ No newline at end of file |
