From 1b91ff7997d2e7782f0154161a0c10a8be8a1d69 Mon Sep 17 00:00:00 2001 From: Jörg Sommrey <28217714+jo-37@users.noreply.github.com> Date: Fri, 4 Oct 2024 13:21:14 +0200 Subject: Solution to task 1 --- challenge-289/jo-37/perl/ch-1.pl | 79 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100755 challenge-289/jo-37/perl/ch-1.pl diff --git a/challenge-289/jo-37/perl/ch-1.pl b/challenge-289/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..0d941f4b6e --- /dev/null +++ b/challenge-289/jo-37/perl/ch-1.pl @@ -0,0 +1,79 @@ +#!/usr/bin/perl -s + +use v5.24; +use Test2::V0; +use warnings FATAL => 'all'; +use Data::Dump qw(dd pp); +use experimental 'signatures'; + +our ($tests, $examples); + +run_tests() if $tests || $examples; # does not return + +die < $max[$i]) { + splice(@max, $i, 0, $n); + $#max = 2; + last i; + } + } + } + + $max[2] > '-inf' ? $max[2] : $max[0]; +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + is third_max(5, 6, 4, 1), 4, 'example 1'; + is third_max(4, 5), 5, 'example 2'; + is third_max(1, 2, 2, 3), 1, 'example 3'; + } + + SKIP: { + skip "tests" unless $tests; + + is third_max(1, 1, 2, 2, 3, 3, 4, 4), 2, 'all doubles'; + is third_max(3, 3, 4, 4), 4, 'no third'; + + + } + + done_testing; + exit; +} -- cgit