diff options
| author | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2024-01-10 21:45:27 +0100 |
|---|---|---|
| committer | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2024-01-12 17:04:07 +0100 |
| commit | 09a6c865607f509af50b9e62249babe849cfa538 (patch) | |
| tree | 8cf6c0521243deb7dcb364fbf1cf3ab5d01b5143 | |
| parent | 6e26b5e5f2133daa14b7ee59adef9a8977b523fe (diff) | |
| download | perlweeklychallenge-club-09a6c865607f509af50b9e62249babe849cfa538.tar.gz perlweeklychallenge-club-09a6c865607f509af50b9e62249babe849cfa538.tar.bz2 perlweeklychallenge-club-09a6c865607f509af50b9e62249babe849cfa538.zip | |
Solution to task 1
| -rwxr-xr-x | challenge-251/jo-37/perl/ch-1.pl | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/challenge-251/jo-37/perl/ch-1.pl b/challenge-251/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..11402fc894 --- /dev/null +++ b/challenge-251/jo-37/perl/ch-1.pl @@ -0,0 +1,58 @@ +#!/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] [N...] + +-examples + run the examples from the challenge + +-tests + run some tests + +N... + list of non-negative integers + +EOS + + +### Input and Output + +say concat_val(@ARGV); + + +### Implementation + +sub concat_val { + my $val = 0; + while (@_) { + $val += shift() . (pop() // ''); + } + $val; +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + is concat_val(6, 12, 25, 1), 1286, 'example 1'; + is concat_val(10, 7, 31, 5, 2, 2), 489, 'example 2'; + is concat_val(1, 2, 10), 112, 'example 3'; + } + + SKIP: { + skip "tests" unless $tests; + } + + done_testing; + exit; +} |
