aboutsummaryrefslogtreecommitdiff
path: root/challenge-053/jo-37/perl/ch-1.pl
blob: 392644fa44092d0ce143cbf78af9d8a147386a9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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;
}