diff options
| author | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2021-09-26 22:08:59 +0200 |
|---|---|---|
| committer | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2021-09-26 22:08:59 +0200 |
| commit | a455aaeef7dc67598f9f569f1ec8a02ece94c1fd (patch) | |
| tree | 919806d8e7e7c290f2d5551dbd846cf0472154da | |
| parent | 60e4e26817bc4a51d12651aef8b52a1d8779e8e3 (diff) | |
| parent | 71bb71465ea2ac4fd44daf84e6572ddc06555924 (diff) | |
| download | perlweeklychallenge-club-a455aaeef7dc67598f9f569f1ec8a02ece94c1fd.tar.gz perlweeklychallenge-club-a455aaeef7dc67598f9f569f1ec8a02ece94c1fd.tar.bz2 perlweeklychallenge-club-a455aaeef7dc67598f9f569f1ec8a02ece94c1fd.zip | |
Solution to challenge 130
| -rwxr-xr-x | challenge-130/jo-37/perl/ch-1.pl | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/challenge-130/jo-37/perl/ch-1.pl b/challenge-130/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..eea4ff7c27 --- /dev/null +++ b/challenge-130/jo-37/perl/ch-1.pl @@ -0,0 +1,57 @@ +#!/usr/bin/perl -s + +use v5.16; +use Test2::V0; +use List::Util qw(pairfirst); +use List::MoreUtils qw(frequency); +use experimental qw(signatures); + +our ($tests, $examples, $verbose); + +run_tests() if $tests || $examples; # does not return + +die <<EOS unless @ARGV; +usage: $0 [-examples] [-tests] [num ...] + +-examples + run the examples from the challenge + +-tests + run some tests + +num ... + numbers + +EOS + + +### Input and Output + +say odd_number(@ARGV); + + +### Implementation + +sub odd_number (@n) { + (pairfirst {$b % 2} frequency @n)[0]; +} + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + is odd_number(2, 5, 4, 4, 5, 5, 2), 5, 'example 1'; + is odd_number(1, 2, 3, 4, 3, 2, 1, 4, 4), 4, 'example 2'; + } + + SKIP: { + skip "tests" unless $tests; + + is odd_number(1, 1, 2, 2), U(), 'no odd number'; + } + + done_testing; + exit; +} |
