diff options
| author | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2024-01-01 16:46:39 +0100 |
|---|---|---|
| committer | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2024-01-05 17:13:30 +0100 |
| commit | 9b5cce9791d577bc1c1b9eb29af0b3db15866ce8 (patch) | |
| tree | c8e68f19533876cb9682eed636913fd8068dbbff | |
| parent | a5df1d5e9605c44e2fd909c192aa8336c66fa103 (diff) | |
| download | perlweeklychallenge-club-9b5cce9791d577bc1c1b9eb29af0b3db15866ce8.tar.gz perlweeklychallenge-club-9b5cce9791d577bc1c1b9eb29af0b3db15866ce8.tar.bz2 perlweeklychallenge-club-9b5cce9791d577bc1c1b9eb29af0b3db15866ce8.zip | |
Solution to task 2
| -rwxr-xr-x | challenge-250/jo-37/perl/ch-2.pl | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/challenge-250/jo-37/perl/ch-2.pl b/challenge-250/jo-37/perl/ch-2.pl new file mode 100755 index 0000000000..e94254968c --- /dev/null +++ b/challenge-250/jo-37/perl/ch-2.pl @@ -0,0 +1,54 @@ +#!/usr/bin/perl -s + +use v5.24; +use Test2::V0; +use List::Util 'max'; + +our ($tests, $examples); + +run_tests() if $tests || $examples; # does not return + +die <<EOS unless @ARGV; +usage: $0 [-examples] [-tests] [...] + +-examples + run the examples from the challenge + +-tests + run some tests + +S... + list of strings + +EOS + + +### Input and Output + +say max_val(@ARGV); + + +### Implementation + +sub max_val { + max map /^\d+$/ ? 0 + $_ : length, @_; +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + is max_val("perl", "2", "000", "python", "r4ku"), 6, 'example 1'; + is max_val("001", "1", "000", "0001"), 1, 'example 2'; + } + + SKIP: { + skip "tests" unless $tests; + } + + done_testing; + exit; +} |
