diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2023-04-09 11:37:06 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-09 11:37:06 +0100 |
| commit | 64ef379dca9b05838fa001212f8249c5f914607b (patch) | |
| tree | 2c63941a5550d06b19b04db99370249b56a4cdb0 | |
| parent | e93e93d38ed2d4546dcdc8267174dd39a9ed88e4 (diff) | |
| parent | 63c6ac5026b1bc34d80101b150d297dd00ab4884 (diff) | |
| download | perlweeklychallenge-club-64ef379dca9b05838fa001212f8249c5f914607b.tar.gz perlweeklychallenge-club-64ef379dca9b05838fa001212f8249c5f914607b.tar.bz2 perlweeklychallenge-club-64ef379dca9b05838fa001212f8249c5f914607b.zip | |
Merge pull request #7869 from carlos157oliveira/challenge-211
solution to challenge 211
| -rw-r--r-- | challenge-211/carlos-oliveira/perl/ch-1.pl | 27 | ||||
| -rw-r--r-- | challenge-211/carlos-oliveira/perl/ch-2.pl | 19 |
2 files changed, 46 insertions, 0 deletions
diff --git a/challenge-211/carlos-oliveira/perl/ch-1.pl b/challenge-211/carlos-oliveira/perl/ch-1.pl new file mode 100644 index 0000000000..bfd6351111 --- /dev/null +++ b/challenge-211/carlos-oliveira/perl/ch-1.pl @@ -0,0 +1,27 @@ +use strict; +use warnings; +use v5.36; + +use Test::More; +use List::Util qw(uniq); + +sub is_toeplitz_matrix (@matrix) { + my $cols = $matrix[0]->@*; + for my $i (0..$#matrix) { + my @diagonal = uniq map { $i < $cols ? $_->[$i++] : () } @matrix; + return 0 unless @diagonal == 1; + } + return 1; +} + +is is_toeplitz_matrix( + [4, 3, 2, 1], + [5, 4, 3, 2], + [6, 5, 4, 3] +), 1; +is is_toeplitz_matrix( + [1, 2, 3], + [3, 2, 1] +), 0; + +done_testing; diff --git a/challenge-211/carlos-oliveira/perl/ch-2.pl b/challenge-211/carlos-oliveira/perl/ch-2.pl new file mode 100644 index 0000000000..421b8e94d7 --- /dev/null +++ b/challenge-211/carlos-oliveira/perl/ch-2.pl @@ -0,0 +1,19 @@ +use strict; +use warnings; +use v5.36; + +use Test::More; +use Algorithm::Combinatorics qw(partitions); +use List::Util qw(any sum uniqnum); +use builtin qw(true false); + +sub can_be_split_with_same_average (@array) { + return any { $_->@* == 1 } + map { [ uniqnum map sum($_->@*) / $_->@*, $_->@* ] } + partitions \@array, 2; +} + +is can_be_split_with_same_average(1, 2, 3, 4, 5, 6, 7, 8), true; +is can_be_split_with_same_average(1, 3), false; + +done_testing; |
