diff options
| author | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2024-05-27 15:50:50 +0200 |
|---|---|---|
| committer | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2024-05-31 14:34:48 +0200 |
| commit | ad64925b28fbe6f6a9743b053151f45a01776bbd (patch) | |
| tree | 3f9d734437519fbaa5fbaac6eba6f6dec3ef1fa1 | |
| parent | 0b65b3658baed21ac9374f6162af8f0d1e3cab59 (diff) | |
| download | perlweeklychallenge-club-ad64925b28fbe6f6a9743b053151f45a01776bbd.tar.gz perlweeklychallenge-club-ad64925b28fbe6f6a9743b053151f45a01776bbd.tar.bz2 perlweeklychallenge-club-ad64925b28fbe6f6a9743b053151f45a01776bbd.zip | |
Solution to task 1
| -rwxr-xr-x | challenge-271/jo-37/perl/ch-1.pl | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/challenge-271/jo-37/perl/ch-1.pl b/challenge-271/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..b218d44fec --- /dev/null +++ b/challenge-271/jo-37/perl/ch-1.pl @@ -0,0 +1,59 @@ +#!/usr/bin/perl -s + +use v5.24; +use Test2::V0 '!float'; +use PDL; + +our ($tests, $examples); + +run_tests() if $tests || $examples; # does not return + +die <<EOS unless @ARGV; +usage: $0 [-examples] [-tests] [M] + +-examples + run the examples from the challenge + +-tests + run some tests + +M + a matrix as accepted by the PDL constructor, e.g. '1, 0; 0, 1' + +EOS + + +### Input and Output + +say maximum_ones(@ARGV); + + +### Implementation +# +# For details see: +# https://github.sommrey.de/the-bears-den/2024/05/31/ch-271.html#task-1 + + +sub maximum_ones { + 1 + maximum_ind sumover pdl @_; +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + is maximum_ones([[0, 1], [1, 0]]), 1, 'example 1'; + is maximum_ones([[0, 0, 0], [1, 0, 1]]), 2, 'example 2'; + is maximum_ones([[0, 0], [1, 1], [0, 0]]), 2, 'example 3'; + } + + SKIP: { + skip "tests" unless $tests; + } + + done_testing; + exit; +} |
