diff options
| author | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2023-10-23 22:23:35 +0200 |
|---|---|---|
| committer | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2023-10-27 17:12:06 +0200 |
| commit | 3bcda3d0efe27a5eeecbd0212fb047719099e101 (patch) | |
| tree | 99b09fe172b65674df1546dcd95a70f7ad40c8ef | |
| parent | 068fea5965668f9ff7381c131c7ac479802a34f8 (diff) | |
| download | perlweeklychallenge-club-3bcda3d0efe27a5eeecbd0212fb047719099e101.tar.gz perlweeklychallenge-club-3bcda3d0efe27a5eeecbd0212fb047719099e101.tar.bz2 perlweeklychallenge-club-3bcda3d0efe27a5eeecbd0212fb047719099e101.zip | |
Solution to task 2
| -rwxr-xr-x | challenge-240/jo-37/perl/ch-2.pl | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/challenge-240/jo-37/perl/ch-2.pl b/challenge-240/jo-37/perl/ch-2.pl new file mode 100755 index 0000000000..6df72e95c8 --- /dev/null +++ b/challenge-240/jo-37/perl/ch-2.pl @@ -0,0 +1,54 @@ +#!/usr/bin/perl -s + +use v5.24; +use Test2::V0; + +our ($tests, $examples); + +run_tests() if $tests || $examples; # does not return + +die <<EOS unless @ARGV; +usage: $0 [-examples] [-tests] [P...] + +-examples + run the examples from the challenge + +-tests + run some tests + +P... + permutation of (0..N-1) + +EOS + + +### Input and Output + +say "(@{build_array(@ARGV)})"; + + +### Implementation + +# Slice the array with itself. + +sub build_array { + [@_[@_]]; +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + is build_array(0, 2, 1, 5, 3, 4), [0, 1, 2, 4, 5, 3], 'example 1'; + is build_array(5, 0, 1, 2, 3, 4), [4, 5, 0, 1, 2, 3], 'example 2'; + } + + SKIP: { + skip "tests" unless $tests; + } + + done_testing; + exit; +} |
