diff options
| author | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2023-04-13 20:38:39 +0200 |
|---|---|---|
| committer | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2023-04-19 18:48:49 +0200 |
| commit | 0c582246b5be6d8005c2a7638531964abc729263 (patch) | |
| tree | 0a899944b634a0edffff6ac520e7bad2fe9ef401 /challenge-053 | |
| parent | 80b89f779427f1705f0796a3d2afd2a9fc0bc06c (diff) | |
| download | perlweeklychallenge-club-0c582246b5be6d8005c2a7638531964abc729263.tar.gz perlweeklychallenge-club-0c582246b5be6d8005c2a7638531964abc729263.tar.bz2 perlweeklychallenge-club-0c582246b5be6d8005c2a7638531964abc729263.zip | |
Challenge 053 task 1
Diffstat (limited to 'challenge-053')
| -rwxr-xr-x | challenge-053/jo-37/perl/ch-1.pl | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/challenge-053/jo-37/perl/ch-1.pl b/challenge-053/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..392644fa44 --- /dev/null +++ b/challenge-053/jo-37/perl/ch-1.pl @@ -0,0 +1,65 @@ +#!/usr/bin/perl -s + +use v5.20; +use Test2::V0 '!float'; +use PDL; +use PDL::NiceSlice; +use experimental 'signatures'; + +our ($tests, $examples, $verbose, $rot); +$rot //= 0; + +run_tests() if $tests || $examples; # does not return + +die <<EOS unless @ARGV; +usage: $0 [-examples] [-tests] [-rot=ROT] [MATRIX] + +-examples + run the examples from the challenge + +-tests + run some tests + +-rot=ROT + rotate given matrix by ROT * 90° clockwise + +MATRIX + a matrix in any form as accepted by the PDL string constructor + +EOS + + +### Input and Output + +main: { + my $m = long "@ARGV"; + $m = rot_m($m) for 1 .. $rot; + say $m; +} + + +### Implementation + +sub rot_m ($m) { + $m->xchg(0,1)->(-1:0); +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + my $m = long [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]; + say $m = rot_m($m) for 1 .. 3; + + } + + SKIP: { + skip "tests" unless $tests; + } + + done_testing; + exit; +} |
