-
Notifications
You must be signed in to change notification settings - Fork 311
/
ch-2.raku
37 lines (28 loc) · 761 Bytes
/
ch-2.raku
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
#!raku
#
# Perl Weekly Challenge 266
# Task 2
#
# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-266>
#
sub MAIN() {
my @matrix = [1, 0, 0, 2],
[0, 3, 4, 0],
[0, 5, 6, 0],
[7, 0, 0, 1],
;
my @indexes;
my $size = @matrix[ 0 ].elems;
for 0 ..^ $size {
@indexes.push: [ $_, $_ ]; # main diagonal
@indexes.push: [ $_, $size - $_ - 1 ]; # antidiagonal
}
my $row-index = 0;
for @matrix -> $row {
my @zeros = $row.grep( { $_ != 0 }, :k ).map( { [ $row-index, $_ ] } );
say 'False' and exit if @zeros.elems != $size / 2;
say 'False' and exit if @indexes.grep( * eq any( @zeros ) ).elems != @zeros.elems;
$row-index++;
}
'True'.say;
}