diff options
| -rwxr-xr-x | challenge-244/jo-37/perl/ch-1.pl | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/challenge-244/jo-37/perl/ch-1.pl b/challenge-244/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..cb67cc00e9 --- /dev/null +++ b/challenge-244/jo-37/perl/ch-1.pl @@ -0,0 +1,55 @@ +#!/usr/bin/perl -s + +use v5.16; +use Test2::V0; +use List::Rank 'rank'; + +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 numbers + +EOS + + +### Input and Output + +say "(@{[count_smaller(@ARGV)]})"; + + +### Implementation + +sub count_smaller { + map tr/=//dr - 1, rank @_; +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + is [count_smaller(8, 1, 2, 2, 3)], [4, 0, 1, 1, 3], 'example 1'; + is [count_smaller(6, 5, 4, 8)], [2, 1, 0, 3], 'example 2'; + is [count_smaller(2, 2, 2)], [0, 0, 0], 'example 3'; + } + + SKIP: { + skip "tests" unless $tests; + } + + done_testing; + exit; +} |
