aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Muth <matthias.muth@gmx.de>2025-09-21 23:11:47 +0200
committerMatthias Muth <matthias.muth@gmx.de>2025-09-21 23:11:47 +0200
commitac3e2fa6bd4f4f617f142739e1d4c47f0ec2fea8 (patch)
tree8ae616213b5d527fcb7ade46ade6a2fe371ef2e9
parentfa4d0c75dc5273373f91dd6b68f26f96742a7d1c (diff)
downloadperlweeklychallenge-club-ac3e2fa6bd4f4f617f142739e1d4c47f0ec2fea8.tar.gz
perlweeklychallenge-club-ac3e2fa6bd4f4f617f142739e1d4c47f0ec2fea8.tar.bz2
perlweeklychallenge-club-ac3e2fa6bd4f4f617f142739e1d4c47f0ec2fea8.zip
Challenge 339 Task 1 and 2 solutions in Perl by Matthias Muth - Update
-rw-r--r--challenge-339/matthias-muth/README.md124
-rw-r--r--challenge-339/matthias-muth/perl/ch-1-full-output.txt111
-rwxr-xr-xchallenge-339/matthias-muth/perl/ch-1.pl107
-rwxr-xr-xchallenge-339/matthias-muth/perl/t/ch-1-full-output.t2
-rwxr-xr-xchallenge-339/matthias-muth/perl/t/ch-1.t2
5 files changed, 260 insertions, 86 deletions
diff --git a/challenge-339/matthias-muth/README.md b/challenge-339/matthias-muth/README.md
index 077f7b2d21..91beadf5c0 100644
--- a/challenge-339/matthias-muth/README.md
+++ b/challenge-339/matthias-muth/README.md
@@ -1,7 +1,5 @@
# Max Complication for Min Brute Force
-# --- DRAFT Work in Progress ---
-
**Challenge 339 solutions in Perl by Matthias Muth**
## Task 1: Max Diff
@@ -62,35 +60,32 @@
> Pair 2: (7, 8)
> ```
-As usual, I try not to use brute force to solve the task. I will *not* do 'combinations', and *not* go through $\binom{n}{4} = \frac{n!}{4!(n-4)!}$ iterations to choose the right numbers.
-
-Instead, I do will do an analysis to learn which numbers to choose.
+As usual, I try not to use brute force to solve the task.<br/>I will *not* do 'combinations', and *not* go through $\binom{n}{4} = \frac{n!}{4!(n-4)!}$ iterations to choose the right numbers.
-My first observation is that for getting the largest difference, the first product has to be as big as possible, and the subtracted number has to be as low as possible. So we can change the task to
+Instead, I will choose a small number of candidate pairs of numbers, based on the numbers' signs and their magnitudes.
-> 'Find two pairs that result in the highest possible product and the lowest possible product, respectively.'
+My first observation is that for getting the largest difference, the first product has to be as high as possible, and the subtracted product has to be as low as possible.
Next observation:<br/>
The largest product can be obtained by multiplying the two largest numbers.<br/>
This should be an obvious one. But there is a huge BUT:
If we have at least two *negative* numbers in our list, and remembering that 'minus times minus equals plus', we might find that the largest (positive) product is obtained by multiplying the two *lowest* numbers (those with the largest absolute amounts).<br/>
-So we have to consider the products of both the two highest positive numbers and the two lowest negative ones, and use the 'better' one.
-
-Thus, the candidates for **the first product** are these:
+So we have to consider the products of both the two highest positive numbers and the two lowest negative ones, and use the 'better' one. If we cannot compute both of them (for example because we don't have any negative numbers in the list), we will only use the one we have.
-* the highest two positive numbers,
-* the lowest two negative numbers (resulting in a positive product).
+So it seems a good idea to separate the positive and the negative numbers into separate arrays, and have them sorted numerically, so that we can access the highest or lowest positive or negative numbers just by indexing into these arrays.
-We need to compare which one is better. If we cannot compute one or the other, we will simply use only the other one.
+For the second pair of numbers, the one whose product we will subtract, we need to find the *lowest* product possible. This is special, because we might get lucky and even get a *negative* product, which would be good because negative numbers are 'low'.
-In any case, it will be good to separate the positive and the negative numbers into separate arrays, and have them sorted numerically, so that we can access the highest or lowest positive or negative numbers just by indexing into these arrays.
+So if we have negative numbers at all, we will use the lowest one (the one with the highest absolute value) that is still available (and was not used for the first product!), together with the highest positive number available.<br/>
+We should then get a product as far in the negative as possible.
-For the number to subtract, we need to find the *lowest* product possible. But this is different, because now we can be lucky and get a negative product, because negative numbers are 'low'.
+Thus, the candidates for **the first product** are these:
-So if we have negative numbers at all, we will be happy to use the lowest one available ((that was not used for the first product!), together with the highest positive number available, to get a negative product as far in the negative as possible.
+* the highest two positive numbers,
+* the lowest two negative numbers (resulting in a positive product).
-So the candidates for **the second product** are these:
+And the candidates for **the second product** are these:
* if we have positive and negative numbers:<br/>
the lowest negative number times the highest positive number,<br/>
@@ -100,21 +95,98 @@ So the candidates for **the second product** are these:
* if we have no positive numbers:<br/>
the two negative numbers closest to zero (or zero itself, if we have one).
-There are cases where the choice for the first product reduce the possible choices for the second product in a way that makes the combination of both not the best choice overall. Especially when there are only few numbers, and the choice of one product reduces the availability of numbers to choose from for the second one.
-
-To be sure, my strategy is to try both:
+Next observation:<br/>
+There can be cases where the choice for the first product reduces the possible choices for the second product in a way that makes the combination of both not the best choice overall. Especially when there are only few numbers, and the choice of one product reduces the availability of numbers to choose from for the other one.
-* The two possible candidates for the best first product, as described above,<br/>combined with the second product chosen from what is left, for each of the candidates separately,
-* the best *second* product chosen from all numbers,<br/>combined with the two possible candidates for the best *first* product from what is left.<br/>Actually we need to consider a third candidate for the first product in this case: If we used a positive and a negative number for the second product, it could be that all we have left is only a 'mixed pair' to use for the first product, something that we didn't need to consider in the cases described above for the first product.
+To be sure to deal correctly with this, my strategy is to try both:
+* Find the two possible candidates for the best *first* product, as described above.<br/>Then choose the best *second* product from the numbers that each of those candidates left.
+* Find the best *second* product chosen from all numbers.<br/>Then choose the best two possible *first* products from what is left.<br/>Actually, in that case, we need to consider a third possible candidate for the first product here: If we used a positive and a negative number for that second product, we might end up with only another 'mixed pair' left, while before, we were sure to have at least two positive *or* two negative numbers for the first pair. So in case we don't succeed in creating either of the two positive candidates for the first pair described above, we need to use what we have and create a negative first product. It still might be a good choice in combination with a good second product.
+My implementations reflects the above, gathering the first and second pair of each different case in an array `@cases`, together with a case number for checking and debugging.<br/>Then, I feed the cases into `map` to compute the differences between the two products for each, with the product computed using `product`, and `max` used to get the best one:
```perl
-sub max_diff() {
- ...;
+use v5.36;
+use List::Util qw( product max );
+
+sub max_diff( @ints ) {
+ my @positives = sort { $b <=> $a } grep $_ >= 0, @ints;
+ my @negatives = sort { $b <=> $a } grep $_ < 0, @ints;
+
+ my @cases = (
+ # Try the highest two positive numbers as the first product,
+ # with the second product as small as possible after having used
+ # those two positive numbers:
+ @positives >= 2 ? do {
+ my $pair_1 = [ @positives[0,1] ];
+ @positives >= 3 && @negatives
+ ? [ "case 1", $pair_1, [ $positives[2], $negatives[-1] ] ] : (),
+ @positives >= 2 && @negatives >= 2
+ ? [ "case 2", $pair_1, [ @negatives[0,1] ] ] : (),
+ @negatives == 0
+ ? [ "case 3", $pair_1, [ @positives[-2,-1] ] ] : (),
+ } : (),
+
+ # Try the lowest two negative numbers as the first product,
+ # with the second product as small as possible after having used
+ # those two negative numbers:
+ @negatives >= 2 ? do {
+ my $pair_1 = [ @negatives[-2,-1] ];
+ @negatives >= 3 && @positives
+ ? [ "case 4", $pair_1, [ $positives[0], $negatives[-3] ] ] : (),
+ @positives >= 2
+ ? [ "case 5", $pair_1, [ @positives[-2,-1] ] ] : (),
+ @positives == 0
+ ? [ "case 6", $pair_1, [ @negatives[0,1] ] ] : (),
+ } : (),
+
+ # Try a negative second product using the best possible 'mixed pair',
+ # with the three options for the first product after that.
+ # For the first product, we then have one less positive and
+ # one less negative available.
+ @negatives && @positives ? do {
+ my $pair_2 = [ $positives[0], $negatives[-1] ];
+ @positives >= 3
+ ? [ "case 7", [ @positives[1,2] ], $pair_2 ] : (),
+ @negatives >= 3
+ ? [ "case 8", [ @negatives[-3,-2] ], $pair_2 ] : (),
+
+ # In case we couldn't create either of the two cases above,
+ # we have to use a 'mixed pair' for the first product:
+ @negatives <= 2 && @positives <= 2
+ ? [ "case 9", [ $positives[1], $negatives[-2] ], $pair_2 ] : (),
+ } : (),
+ );
+
+ return
+ max( map product( $_->[1]->@* ) - product( $_->[2]->@* ), @cases );
}
```
+My actual code (on [github](https://github.com/MatthiasMuth/perlweeklychallenge-club/blob/muthm-339/challenge-339/matthias-muth/perl/)) includes some additions for checking and debugging. The function can return the case number and the two number pairs that lead to the best combination if it is used in list context.
+
+I also wrote two test scripts with additional tests. As most tests in Perl should , they reside in the [`t` subdirectory](https://github.com/MatthiasMuth/perlweeklychallenge-club/tree/muthm-339/challenge-339/matthias-muth/perl/t) , so that `prove` can be used to run them.
+
+The [`t/ch-1-full-output.t`](https://github.com/MatthiasMuth/perlweeklychallenge-club/blob/muthm-339/challenge-339/matthias-muth/perl/t/ch-1-full-output.t) test script makes use of the added return values, and prints out which case was used for which test case, in the style used in the task description (see [`ch-1-full-output.txt`](https://github.com/MatthiasMuth/perlweeklychallenge-club/blob/muthm-339/challenge-339/matthias-muth/perl/ch-1-full-output.txt) for the captured output).
+
+These are the counts from the tests for each of the cases, showing that actually none of them is redundant:
+
+```text
+case 1: 6 times
+case 2: 9 times
+case 3: 4 times
+case 4: 5 times
+case 5: 9 times
+case 6: 2 times
+case 7: 2 times
+case 8: 1 time
+case 9: 7 times
+```
+
+This might easily be the Weekly Challenge task that caused me longest to complete!<br/>Not only because it took some effort finding the cases, but I also changed the code structure several times until I was happy enough with the readability of the code.
+
+I love this challenge!
+
## Task 2: Peak Point
> You are given an array of altitude gain.<br/>
@@ -197,9 +269,11 @@ sub max_diff() {
> max(0, -10, 5, 10) = 10
> ```
+If the first task took me quite a bit of effort, the second task was really easy.
+I use `reductions` to compute the running sum of the input numbers, and with `reductions` returning all intermediate results, these intermediate results happen to be the altitudes that we want to get the maximum of.
-
+So the task can be solved in a single line:
```perl
use v5.36;
diff --git a/challenge-339/matthias-muth/perl/ch-1-full-output.txt b/challenge-339/matthias-muth/perl/ch-1-full-output.txt
new file mode 100644
index 0000000000..c3b1d05bd5
--- /dev/null
+++ b/challenge-339/matthias-muth/perl/ch-1-full-output.txt
@@ -0,0 +1,111 @@
+ok 1 - Test 0: max_diff( 5, 4, 3, 2 ) == 14
+# Pair 1: ( 5, 4 )
+# Pair 2: ( 3, 2 )
+# Product Diff: ( 5 * 4 ) - ( 3 * 2 ) => ( 20 - 6 ) => 14
+#
+ok 2 - Test 1: max_diff( -5, 4, 3, 2 ) == 26
+# Pair 1: ( 3, 2 )
+# Pair 2: ( 4, -5 )
+# Product Diff: ( 3 * 2 ) - ( 4 * -5 ) => ( 6 - (-20) ) => 26
+#
+ok 3 - Test 2: max_diff( 5, -4, 3, 2 ) == 26
+# Pair 1: ( 3, 2 )
+# Pair 2: ( 5, -4 )
+# Product Diff: ( 3 * 2 ) - ( 5 * -4 ) => ( 6 - (-20) ) => 26
+#
+ok 4 - Test 3: max_diff( -5, -4, 3, 2 ) == 14
+# Pair 1: ( -4, -5 )
+# Pair 2: ( 3, 2 )
+# Product Diff: ( -4 * -5 ) - ( 3 * 2 ) => ( 20 - 6 ) => 14
+#
+ok 5 - Test 4: max_diff( 5, 4, -3, 2 ) == 26
+# Pair 1: ( 5, 4 )
+# Pair 2: ( 2, -3 )
+# Product Diff: ( 5 * 4 ) - ( 2 * -3 ) => ( 20 - (-6) ) => 26
+#
+ok 6 - Test 5: max_diff( -5, 4, -3, 2 ) == 14
+# Pair 1: ( 2, -3 )
+# Pair 2: ( 4, -5 )
+# Product Diff: ( 2 * -3 ) - ( 4 * -5 ) => ( (-6) - (-20) ) => 14
+#
+ok 7 - Test 6: max_diff( 5, -4, -3, 2 ) == 14
+# Pair 1: ( 2, -3 )
+# Pair 2: ( 5, -4 )
+# Product Diff: ( 2 * -3 ) - ( 5 * -4 ) => ( (-6) - (-20) ) => 14
+#
+ok 8 - Test 7: max_diff( -5, -4, -3, 2 ) == 26
+# Pair 1: ( -4, -5 )
+# Pair 2: ( 2, -3 )
+# Product Diff: ( -4 * -5 ) - ( 2 * -3 ) => ( 20 - (-6) ) => 26
+#
+ok 9 - Test 8: max_diff( 5, 4, 3, -2 ) == 26
+# Pair 1: ( 5, 4 )
+# Pair 2: ( 3, -2 )
+# Product Diff: ( 5 * 4 ) - ( 3 * -2 ) => ( 20 - (-6) ) => 26
+#
+ok 10 - Test 9: max_diff( -5, 4, 3, -2 ) == 14
+# Pair 1: ( 3, -2 )
+# Pair 2: ( 4, -5 )
+# Product Diff: ( 3 * -2 ) - ( 4 * -5 ) => ( (-6) - (-20) ) => 14
+#
+ok 11 - Test 10: max_diff( 5, -4, 3, -2 ) == 14
+# Pair 1: ( 3, -2 )
+# Pair 2: ( 5, -4 )
+# Product Diff: ( 3 * -2 ) - ( 5 * -4 ) => ( (-6) - (-20) ) => 14
+#
+ok 12 - Test 11: max_diff( -5, -4, 3, -2 ) == 26
+# Pair 1: ( -4, -5 )
+# Pair 2: ( 3, -2 )
+# Product Diff: ( -4 * -5 ) - ( 3 * -2 ) => ( 20 - (-6) ) => 26
+#
+ok 13 - Test 12: max_diff( 5, 4, -3, -2 ) == 14
+# Pair 1: ( 5, 4 )
+# Pair 2: ( -2, -3 )
+# Product Diff: ( 5 * 4 ) - ( -2 * -3 ) => ( 20 - 6 ) => 14
+#
+ok 14 - Test 13: max_diff( -5, 4, -3, -2 ) == 26
+# Pair 1: ( -2, -3 )
+# Pair 2: ( 4, -5 )
+# Product Diff: ( -2 * -3 ) - ( 4 * -5 ) => ( 6 - (-20) ) => 26
+#
+ok 15 - Test 14: max_diff( 5, -4, -3, -2 ) == 26
+# Pair 1: ( -2, -3 )
+# Pair 2: ( 5, -4 )
+# Product Diff: ( -2 * -3 ) - ( 5 * -4 ) => ( 6 - (-20) ) => 26
+#
+ok 16 - Test 15: max_diff( -5, -4, -3, -2 ) == 14
+# Pair 1: ( -4, -5 )
+# Pair 2: ( -2, -3 )
+# Product Diff: ( -4 * -5 ) - ( -2 * -3 ) => ( 20 - 6 ) => 14
+#
+ok 17 - Test 16 (201 numbers): max_diff( -100, -99, -98, -97, -96, -95, -94, -93, -92, -91, -90, -89, -88, -87, -86, -85, -84, -83, -82, -81, -80, -79, -78, -77, -76, -75, -74, -73, -72, -71, -70, -69, -68, -67, -66, -65, -64, -63, -62, -61, -60, -59, -58, -57, -56, -55, -54, -53, -52, -51, -50, -49, -48, -47, -46, -45, -44, -43, -42, -41, -40, -39, -38, -37, -36, -35, -34, -33, -32, -31, -30, -29, -28, -27, -26, -25, -24, -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100 ) == 19702
+# Pair 1: ( 99, 98 )
+# Pair 2: ( 100, -100 )
+# Product Diff: ( 99 * 98 ) - ( 100 * -100 ) => ( 9702 - (-10000) ) => 19702
+#
+ok 18 - Example 1: max_diff( 5, 9, 3, 4, 6 ) == 42
+# Pair 1: ( 9, 6 )
+# Pair 2: ( 4, 3 )
+# Product Diff: ( 9 * 6 ) - ( 4 * 3 ) => ( 54 - 12 ) => 42
+#
+ok 19 - Example 2: max_diff( 1, -2, 3, -4 ) == 10
+# Pair 1: ( 1, -2 )
+# Pair 2: ( 3, -4 )
+# Product Diff: ( 1 * -2 ) - ( 3 * -4 ) => ( (-2) - (-12) ) => 10
+#
+ok 20 - Example 3: max_diff( -3, -1, -2, -4 ) == 10
+# Pair 1: ( -3, -4 )
+# Pair 2: ( -1, -2 )
+# Product Diff: ( -3 * -4 ) - ( -1 * -2 ) => ( 12 - 2 ) => 10
+#
+ok 21 - Example 4: max_diff( 10, 2, 0, 5, 1 ) == 50
+# Pair 1: ( 10, 5 )
+# Pair 2: ( 1, 0 )
+# Product Diff: ( 10 * 5 ) - ( 1 * 0 ) => ( 50 - 0 ) => 50
+#
+ok 22 - Example 5: max_diff( 7, 8, 9, 10, 10 ) == 44
+# Pair 1: ( 10, 10 )
+# Pair 2: ( 8, 7 )
+# Product Diff: ( 10 * 10 ) - ( 8 * 7 ) => ( 100 - 56 ) => 44
+#
+1..22
diff --git a/challenge-339/matthias-muth/perl/ch-1.pl b/challenge-339/matthias-muth/perl/ch-1.pl
index 8592bc1e8e..d6cff5c30d 100755
--- a/challenge-339/matthias-muth/perl/ch-1.pl
+++ b/challenge-339/matthias-muth/perl/ch-1.pl
@@ -9,7 +9,8 @@
#
use v5.36;
-use builtin qw( true false );
+
+use Dsay;
use List::Util qw( product max first );
@@ -17,68 +18,52 @@ sub max_diff( @ints ) {
my @positives = sort { $b <=> $a } grep $_ >= 0, @ints;
my @negatives = sort { $b <=> $a } grep $_ < 0, @ints;
- my @cases;
-
- # Try the highest two positive numbers as the first product,
- # with the second product as small as possible after having used
- # those two positive numbers:
- if ( @positives >= 2 ) {
- push @cases, [ "case 1",
- [ @positives[0,1] ],
- @negatives
- ? @positives >= 3
- ? [ $positives[2], $negatives[-1] ]
- : [ @negatives[0,1] ]
- : [ @positives[-2,-1] ]
- ];
- }
+ my @cases = (
+ # Try the highest two positive numbers as the first product,
+ # with the second product as small as possible after having used
+ # those two positive numbers:
+ @positives >= 2 ? do {
+ my $pair_1 = [ @positives[0,1] ];
+ @positives >= 3 && @negatives
+ ? [ "case 1", $pair_1, [ $positives[2], $negatives[-1] ] ] : (),
+ @positives >= 2 && @negatives >= 2
+ ? [ "case 2", $pair_1, [ @negatives[0,1] ] ] : (),
+ @negatives == 0
+ ? [ "case 3", $pair_1, [ @positives[-2,-1] ] ] : (),
+ } : (),
- # Try the lowest two negative numbers as the first product:
- # with the second product as small as possible after having used
- # those two negative numbers:
- if ( @negatives >= 2 ) {
- push @cases, [ "case 2",
- [ @negatives[-2,-1] ],
- @negatives >= 3
- ? @positives
- ? [ $positives[0], $negatives[-3] ]
- : [ @negatives[0,1] ]
- : [ @positives[-2,-1] ]
- ];
- }
+ # Try the lowest two negative numbers as the first product,
+ # with the second product as small as possible after having used
+ # those two negative numbers:
+ @negatives >= 2 ? do {
+ my $pair_1 = [ @negatives[-2,-1] ];
+ @negatives >= 3 && @positives
+ ? [ "case 4", $pair_1, [ $positives[0], $negatives[-3] ] ] : (),
+ @positives >= 2
+ ? [ "case 5", $pair_1, [ @positives[-2,-1] ] ] : (),
+ @positives == 0
+ ? [ "case 6", $pair_1, [ @negatives[0,1] ] ] : (),
+ } : (),
- # Try the lowest *second* product first,
- # with the three options for the first product after that.
- if ( @negatives && @positives ) {
- # We have negatives and positives.
- # Use the best possible mixed pair for the second product.
+ # Try a negative second product using the best possible 'mixed pair',
+ # with the three options for the first product after that.
# For the first product, we then have one less positive and
# one less negative available.
- my $got_positive_first_product = false;
- if ( @positives >= 3 ) {
- push @cases, [ "case 3",
- [ @positives[1,2] ],
- [ $positives[0], $negatives[-1] ],
- ];
- $got_positive_first_product = true;
- }
- if ( @negatives >= 3 ) {
- push @cases, [ "case 4",
- [ @negatives[-3,-2] ],
- [ $positives[0], $negatives[-1] ],
- ];
- $got_positive_first_product = true;
- }
- # In case we couldn't create either of the two cases above,
- # we have to use a 'mixed pair' for the first product:
- unless ( $got_positive_first_product ) {
- push @cases, [ "case 5",
- [ $positives[1], $negatives[-2] ],
- [ $positives[0], $negatives[-1] ]
- ];
- }
- }
+ @negatives && @positives ? do {
+ my $pair_2 = [ $positives[0], $negatives[-1] ];
+ @positives >= 3
+ ? [ "case 7", [ @positives[1,2] ], $pair_2 ] : (),
+ @negatives >= 3
+ ? [ "case 8", [ @negatives[-3,-2] ], $pair_2 ] : (),
+
+ # In case we couldn't create either of the two cases above,
+ # we have to use a 'mixed pair' for the first product:
+ @negatives <= 2 && @positives <= 2
+ ? [ "case 9", [ $positives[1], $negatives[-2] ], $pair_2 ] : (),
+ } : (),
+ );
+ dsay pp @cases;
my $maximum =
max( map product( $_->[1]->@* ) - product( $_->[2]->@* ), @cases );
@@ -91,7 +76,7 @@ sub max_diff( @ints ) {
# the maximum.
( $maximum,
map $_->@[1,2],
- first {
+ first {
product( $_->[1]->@* ) - product( $_->[2]->@* )
== $maximum
} @cases
@@ -100,8 +85,8 @@ sub max_diff( @ints ) {
: $maximum;
}
-# Allow for including this script for the function definitioni, but without
-# executing the tests:
+# Allow for including this script for the function definition
+# (using 'require' or 'use'), but without executing the tests:
unless ( caller ) {
use Test2::V0 qw( -no_srand );
diff --git a/challenge-339/matthias-muth/perl/t/ch-1-full-output.t b/challenge-339/matthias-muth/perl/t/ch-1-full-output.t
index ea3ce416c7..0798f564d7 100755
--- a/challenge-339/matthias-muth/perl/t/ch-1-full-output.t
+++ b/challenge-339/matthias-muth/perl/t/ch-1-full-output.t
@@ -35,6 +35,8 @@ my @tests = (
[ "Test 16 (201 numbers)", [ -100..+100 ], 19702 ],
+ [ "Test 17 (Egon Choroba)", [ qw( 16 12 4 -25 -23 9 10 ) ], 539 ],
+
[ "Example 1", [ 5, 9, 3, 4, 6 ], 42 ],
[ "Example 2", [ 1, -2, 3, -4 ], 10 ],
[ "Example 3", [ -3, -1, -2, -4 ], 10 ],
diff --git a/challenge-339/matthias-muth/perl/t/ch-1.t b/challenge-339/matthias-muth/perl/t/ch-1.t
index 15b76466cc..eec6871eb4 100755
--- a/challenge-339/matthias-muth/perl/t/ch-1.t
+++ b/challenge-339/matthias-muth/perl/t/ch-1.t
@@ -35,6 +35,8 @@ my @tests = (
[ "Test 16 (201 numbers)", [ -100..+100 ], 19702 ],
+ [ "Test 17 (Egon Choroba)", [ qw( 16 12 4 -25 -23 9 10 ) ], 539 ],
+
[ "Example 1", [ 5, 9, 3, 4, 6 ], 42 ],
[ "Example 2", [ 1, -2, 3, -4 ], 10 ],
[ "Example 3", [ -3, -1, -2, -4 ], 10 ],