From 011eecc4681e6e6ae327ba316b4735b0c84d9870 Mon Sep 17 00:00:00 2001 From: Jörg Sommrey <28217714+jo-37@users.noreply.github.com> Date: Tue, 3 Jan 2023 22:17:02 +0100 Subject: Solution to task 1 --- challenge-198/jo-37/perl/ch-1.pl | 67 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 challenge-198/jo-37/perl/ch-1.pl diff --git a/challenge-198/jo-37/perl/ch-1.pl b/challenge-198/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..c406cbc810 --- /dev/null +++ b/challenge-198/jo-37/perl/ch-1.pl @@ -0,0 +1,67 @@ +#!/usr/bin/perl -s + +use v5.16; +use Test2::V0 '!float'; +use PDL; + +our ($tests, $examples); + +run_tests() if $tests || $examples; # does not return + +die < 1; + my $gap = sumover long(@_)->qsort->lags(0, 1, 2)->xchg(0, 1) * long 1, -1; + + $gap->where($gap == max $gap)->dim(0); +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + is count_max_gap(qw(2 5 8 1)), 2, 'example 1'; + is count_max_gap(3), 0, 'example 2'; + } + + SKIP: { + skip "tests" unless $tests; + + is count_max_gap(qw(8 6 4 3 2 1)), 2, 'max count not at max gap'; + is count_max_gap(qw(3 3 3)), 2, 'zero gap'; + is count_max_gap(qw(5 3 2 1)), 1, 'single max gap'; + is count_max_gap(qw(1 2 3 -1)), 1, 'negative number in max gap'; + is count_max_gap(2, 1), 1, 'single gap'; + is count_max_gap(), 0, 'empty list'; + } + + done_testing; + exit; +} -- cgit From 4012ef282b2effc208bb550f301fbe0937f430e2 Mon Sep 17 00:00:00 2001 From: Jörg Sommrey <28217714+jo-37@users.noreply.github.com> Date: Tue, 3 Jan 2023 22:17:17 +0100 Subject: Solution to task 2 --- challenge-198/jo-37/perl/ch-2.sh | 5 +++++ 1 file changed, 5 insertions(+) create mode 100755 challenge-198/jo-37/perl/ch-2.sh diff --git a/challenge-198/jo-37/perl/ch-2.sh b/challenge-198/jo-37/perl/ch-2.sh new file mode 100755 index 0000000000..14174f9d2b --- /dev/null +++ b/challenge-198/jo-37/perl/ch-2.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +# "prime_count" has inclusive ranges, so we need to adjust the limit. +# This neat subtlety was carefully avoided in the examples. +perl -MMath::Prime::Util=:all -E "say prime_count $1 - 1" -- cgit