diff options
| -rw-r--r-- | challenge-269/jo-37/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-269/jo-37/perl/ch-1.pl | 58 | ||||
| -rwxr-xr-x | challenge-269/jo-37/perl/ch-2.pl | 64 |
3 files changed, 123 insertions, 0 deletions
diff --git a/challenge-269/jo-37/blog.txt b/challenge-269/jo-37/blog.txt new file mode 100644 index 0000000000..44557c55db --- /dev/null +++ b/challenge-269/jo-37/blog.txt @@ -0,0 +1 @@ +https://github.sommrey.de/the-bears-den/2024/05/17/ch-269.html diff --git a/challenge-269/jo-37/perl/ch-1.pl b/challenge-269/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..9876b7ee39 --- /dev/null +++ b/challenge-269/jo-37/perl/ch-1.pl @@ -0,0 +1,58 @@ +#!/usr/bin/perl -s + +use v5.26; +use Test2::V0; + +our ($tests, $examples); + +run_tests() if $tests || $examples; # does not return + +die <<EOS unless @ARGV; +usage: $0 [-examples] [-tests] [I...] + +-examples + run the examples from the challenge + +-tests + run some tests + +I... + list of integers + +EOS + + +### Input and Output + +say +(qw(false true))[mtz(@ARGV)]; + + +### Implementation +# +# For details see: +# https://github.sommrey.de/the-bears-den/2024/05/17/ch-269.html#task-1 + + +sub mtz { + 1 < grep !($_ & 1), @_; +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + ok mtz(1, 2, 3, 4, 5), 'example 1'; + ok mtz(2, 3, 8, 16), 'example 2'; + ok !mtz(1, 2, 5, 7, 9), 'example 3'; + } + + SKIP: { + skip "tests" unless $tests; + } + + done_testing; + exit; +} diff --git a/challenge-269/jo-37/perl/ch-2.pl b/challenge-269/jo-37/perl/ch-2.pl new file mode 100755 index 0000000000..ba82d29b33 --- /dev/null +++ b/challenge-269/jo-37/perl/ch-2.pl @@ -0,0 +1,64 @@ +#!/usr/bin/perl -s + +use v5.24; +use Test2::V0; +use POSIX qw(Inf NaN); + +our ($tests, $examples); + +run_tests() if $tests || $examples; # does not return + +die <<EOS unless @ARGV; +usage: $0 [-examples] [-tests] [I...] + +-examples + run the examples from the challenge + +-tests + run some tests + +I... + list of integers + +EOS + + +### Input and Output + +say "(@{[join ', ', de(@ARGV)]})"; + + +### Implementation +# +# For details see: +# https://github.sommrey.de/the-bears-den/2024/05/17/ch-269.html#task-2 + + +sub de { + my @arr; + push @{$arr[($arr[0][-1] // NaN) <= ($arr[1][-1] // Inf)]}, $_ for @_; + map @$_, @arr; +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + is [de(2, 1, 3, 4, 5)], [2, 3, 4, 5, 1], 'example 1'; + is [de(3, 2, 4)], [3, 4, 2], 'example 2'; + is [de(5, 4, 3, 8)], [5, 3, 4, 8], 'example 3'; + } + + SKIP: { + skip "tests" unless $tests; + + is [de(2, 1, 1, 3)], [2, 1, 1, 3], 'not unique'; + + } + + done_testing; + exit; +} |
