From 15c11d149b4513fcdaad12e0ae08a75e05c81d0a Mon Sep 17 00:00:00 2001 From: Jörg Sommrey <28217714+jo-37@users.noreply.github.com> Date: Fri, 13 Sep 2024 11:29:38 +0200 Subject: Solution to task 2 --- challenge-286/jo-37/perl/ch-2.pl | 73 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 challenge-286/jo-37/perl/ch-2.pl diff --git a/challenge-286/jo-37/perl/ch-2.pl b/challenge-286/jo-37/perl/ch-2.pl new file mode 100755 index 0000000000..be2640fab7 --- /dev/null +++ b/challenge-286/jo-37/perl/ch-2.pl @@ -0,0 +1,73 @@ +#!/usr/bin/perl -s + +use v5.24; +use Test2::V0; +use experimental 'signatures'; + +our ($tests, $examples, $verbose); + +run_tests() if $tests || $examples; # does not return + +die < 1) { + my ($i, $k) = splice @ints, 0, 2; + push @ints, ($f *= -1) * ($k - $i) > 0 ? $k : $i; + say "@ints" if $verbose; + } + shift @ints; +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + is order_game(2, 1, 4, 5, 6, 3, 0, 2), 1, 'example 1'; + is order_game(0, 5, 3, 2), 0, 'example 2'; + is order_game(9, 2, 1, 4, 5, 6, 0, 7, 3, 1, 3, 5, 7, 9, 0, 8), + 2, 'example 3'; + } + + SKIP: { + skip "tests" unless $tests; + + is order_game(3, 2, 1), 2, 'not a power of two'; + + } + + done_testing; + exit; +} -- cgit