diff options
| author | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-09-15 23:14:39 +0100 |
|---|---|---|
| committer | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-09-15 23:14:39 +0100 |
| commit | 9b49b3c00a595fbb7441615fea79b7fbc2694c99 (patch) | |
| tree | f75f7e7ff98d0103413a6adf03513ed65dd6777c | |
| parent | 7f78d729369f524a8bf4d7d9eb693aa689d78af6 (diff) | |
| download | perlweeklychallenge-club-9b49b3c00a595fbb7441615fea79b7fbc2694c99.tar.gz perlweeklychallenge-club-9b49b3c00a595fbb7441615fea79b7fbc2694c99.tar.bz2 perlweeklychallenge-club-9b49b3c00a595fbb7441615fea79b7fbc2694c99.zip | |
- Added solutions by Andreas Mahnke.
- Added solutions by E. Choroba.
- Added solutions by Eric Cheung.
- Added solutions by W. Luis Mochan.
- Added solutions by Peter Campbell Smith.
- Added solutions by Peter Meszaros.
- Added solutions by Thomas Kohler.
26 files changed, 211 insertions, 78 deletions
diff --git a/challenge-339/eric-cheung/python/ch-1.py b/challenge-339/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..9e84200c90 --- /dev/null +++ b/challenge-339/eric-cheung/python/ch-1.py @@ -0,0 +1,17 @@ +
+from math import prod
+
+## Ref.:
+
+## arrInts = [5, 9, 3, 4, 6] ## Example 1
+## arrInts = [1, -2, 3, -4] ## Example 2
+## arrInts = [-3, -1, -2, -4] ## Example 3
+## arrInts = [10, 2, 0, 5, 1] ## Example 4
+arrInts = [7, 8, 9, 10, 10] ## Example 5
+
+arrInts = sorted(arrInts)
+
+if all(nElem >= 0 for nElem in arrInts) or all(nElem <= 0 for nElem in arrInts):
+ print (abs(prod(arrInts[-2:]) - prod(arrInts[:2])))
+else:
+ print (arrInts[-3] * arrInts[-2] - arrInts[0] * arrInts[-1])
diff --git a/challenge-339/eric-cheung/python/ch-2.py b/challenge-339/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..08f9ccac92 --- /dev/null +++ b/challenge-339/eric-cheung/python/ch-2.py @@ -0,0 +1,11 @@ +
+## arrGain = [-5, 1, 5, -9, 2] ## Example 1
+## arrGain = [10, 10, 10, -25] ## Example 2
+## arrGain = [3, -4, 2, 5, -6, 1] ## Example 3
+## arrGain = [-1, -2, -3, -4] ## Example 4
+arrGain = [-10, 15, 5] ## Example 5
+
+arrOutput = [0]
+arrOutput = arrOutput + [sum(arrGain[:nIndx + 1]) for nIndx in range(len(arrGain))]
+
+print (max(arrOutput))
diff --git a/challenge-339/mohammad-anwar/perl/ch-1.pl b/challenge-339/mohammad-anwar/perl/ch-1.pl index 265579d0a8..b6944cacd4 100644 --- a/challenge-339/mohammad-anwar/perl/ch-1.pl +++ b/challenge-339/mohammad-anwar/perl/ch-1.pl @@ -20,23 +20,26 @@ sub max_diff { # For larger arrays, we need to consider extreme values my @s = sort {$a <=> $b} @nums; - - # The maximum difference will likely come from: - # Option 1: (two largest) vs (two smallest) - # Option 2: (largest*smallest) vs (second largest*second smallest) - # Option 3: (largest*second smallest) vs (second largest*smallest) - - my $opt1 = $s[-1]*$s[-2] - $s[0]*$s[1]; - my $opt2 = $s[-1]*$s[0] - $s[-2]*$s[1]; - my $opt3 = $s[-1]*$s[1] - $s[-2]*$s[0]; - - return max($opt1, $opt2, $opt3); + my ($l1, $l2, $l3, $s1, $s2, $s3) = + ($s[-1], $s[-2], $s[-3], $s[0], $s[1], $s[2]); + + my $opt1 = $l1*$l2 - $s1*$s2; + my $opt2 = $l1*$s1 - $l2*$s2; + my $opt3 = $l1*$s2 - $l2*$s1; + my $opt4 = $l1*$l2 - $l1*$s3; + my $opt5 = $s1*$s2 - $l1*$s3; + my $opt6 = $s1*$l3 - $l1*$s1; + my $opt7 = $s2*$s3 - $l1*$s1; + + return max($opt1, $opt2, $opt3, $opt4, $opt5, $opt6, $opt7); } -is(max_diff(5,9,3,4,6), 42); -is(max_diff(1,-2,3,-4), 10); -is(max_diff(-3,-1,-2,-4), 10); -is(max_diff(10,2,0,5,1), 50); -is(max_diff(7,8,9,10,10), 44); +is(max_diff(5,9,3,4,6), 42); +is(max_diff(1,-2,3,-4), 10); +is(max_diff(-3,-1,-2,-4), 10); +is(max_diff(10,2,0,5,1), 50); +is(max_diff(7,8,9,10,10), 44); +is(max_diff(-1,0,1,2,3,4,5), 23); +is(max_diff(-10,0,1,2,3,4,5), 62); done_testing; diff --git a/stats/pwc-current.json b/stats/pwc-current.json index 9dbb5ad55a..6d33c583a0 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -7,6 +7,26 @@ { "data" : [ [ + "Perl", + 2 + ] + ], + "id" : "Andreas Mahnke", + "name" : "Andreas Mahnke" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "E. Choroba", + "name" : "E. Choroba" + }, + { + "data" : [ + [ "Raku", 2 ] @@ -37,6 +57,30 @@ { "data" : [ [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Peter Campbell Smith", + "name" : "Peter Campbell Smith" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Peter Meszaros", + "name" : "Peter Meszaros" + }, + { + "data" : [ + [ "Raku", 2 ] @@ -51,12 +95,40 @@ 2 ], [ + "Blog", + 2 + ] + ], + "id" : "Thomas Kohler", + "name" : "Thomas Kohler" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ "Raku", 2 ] ], "id" : "Ulrich Rieke", "name" : "Ulrich Rieke" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "W. Luis Mochan", + "name" : "W. Luis Mochan" } ] }, @@ -77,6 +149,16 @@ "colorByPoint" : 1, "data" : [ { + "drilldown" : "Andreas Mahnke", + "name" : "Andreas Mahnke", + "y" : 2 + }, + { + "drilldown" : "E. Choroba", + "name" : "E. Choroba", + "y" : 2 + }, + { "drilldown" : "Feng Chang", "name" : "Feng Chang", "y" : 2 @@ -92,21 +174,41 @@ "y" : 2 }, { + "drilldown" : "Peter Campbell Smith", + "name" : "Peter Campbell Smith", + "y" : 3 + }, + { + "drilldown" : "Peter Meszaros", + "name" : "Peter Meszaros", + "y" : 2 + }, + { "drilldown" : "Simon Proctor", "name" : "Simon Proctor", "y" : 2 }, { + "drilldown" : "Thomas Kohler", + "name" : "Thomas Kohler", + "y" : 4 + }, + { "drilldown" : "Ulrich Rieke", "name" : "Ulrich Rieke", "y" : 4 + }, + { + "drilldown" : "W. Luis Mochan", + "name" : "W. Luis Mochan", + "y" : 3 } ], "name" : "The Weekly Challenge - 339" } ], "subtitle" : { - "text" : "[Champions: 5] Last updated at 2025-09-15 10:18:43 GMT" + "text" : "[Champions: 11] Last updated at 2025-09-15 22:12:18 GMT" }, "title" : { "text" : "The Weekly Challenge - 339" diff --git a/stats/pwc-language-breakdown-2019.json b/stats/pwc-language-breakdown-2019.json index 8416a0d9c6..3a170fa452 100644 --- a/stats/pwc-language-breakdown-2019.json +++ b/stats/pwc-language-breakdown-2019.json @@ -970,7 +970,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-09-15 10:18:43 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-09-15 22:12:18 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2020.json b/stats/pwc-language-breakdown-2020.json index f28802ecb4..bc8b2736b0 100644 --- a/stats/pwc-language-breakdown-2020.json +++ b/stats/pwc-language-breakdown-2020.json @@ -1223,7 +1223,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-09-15 10:18:43 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-09-15 22:12:18 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2021.json b/stats/pwc-language-breakdown-2021.json index dfcff0f82e..41dfba7139 100644 --- a/stats/pwc-language-breakdown-2021.json +++ b/stats/pwc-language-breakdown-2021.json @@ -1223,7 +1223,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-09-15 10:18:43 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-09-15 22:12:18 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2022.json b/stats/pwc-language-breakdown-2022.json index 4608f8823f..9104256deb 100644 --- a/stats/pwc-language-breakdown-2022.json +++ b/stats/pwc-language-breakdown-2022.json @@ -1223,7 +1223,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-09-15 10:18:43 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-09-15 22:12:18 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2023.json b/stats/pwc-language-breakdown-2023.json index 7b2ba07e7e..e1d978a4e9 100644 --- a/stats/pwc-language-breakdown-2023.json +++ b/stats/pwc-language-breakdown-2023.json @@ -1200,7 +1200,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-09-15 10:18:43 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-09-15 22:12:18 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2024.json b/stats/pwc-language-breakdown-2024.json index ab8c345711..adbcb358c9 100644 --- a/stats/pwc-language-breakdown-2024.json +++ b/stats/pwc-language-breakdown-2024.json @@ -1246,7 +1246,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-09-15 10:18:43 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-09-15 22:12:18 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2025.json b/stats/pwc-language-breakdown-2025.json index 0fb548af79..ae0bb6bc8b 100644 --- a/stats/pwc-language-breakdown-2025.json +++ b/stats/pwc-language-breakdown-2025.json @@ -8,7 +8,7 @@ "data" : [ [ "Perl", - 5 + 17 ], [ "Raku", @@ -16,7 +16,7 @@ ], [ "Blog", - 0 + 4 ] ], "id" : "339", @@ -691,7 +691,7 @@ { "drilldown" : "339", "name" : "339", - "y" : 11 + "y" : 27 }, { "drilldown" : "338", @@ -878,7 +878,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-09-15 10:18:43 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-09-15 22:12:18 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index b3b379aa97..4cee30198d 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -10,7 +10,7 @@ "data" : [ [ "Perl", - 17438 + 17450 ], [ "Raku", @@ -18,7 +18,7 @@ ], [ "Blog", - 6259 + 6263 ] ], "dataLabels" : { @@ -37,7 +37,7 @@ } ], "subtitle" : { - "text" : "Last updated at 2025-09-15 10:18:43 GMT" + "text" : "Last updated at 2025-09-15 22:12:18 GMT" }, "title" : { "text" : "The Weekly Challenge Contributions [2019 - 2025]" diff --git a/stats/pwc-leaders.json b/stats/pwc-leaders.json index cf73616364..9e07ff5369 100644 --- a/stats/pwc-leaders.json +++ b/stats/pwc-leaders.json @@ -176,7 +176,7 @@ "data" : [ [ "Perl", - 494 + 496 ], [ "Raku", @@ -184,7 +184,7 @@ ], [ "Blog", - 247 + 248 ] ], "id" : "W. Luis Mochan", @@ -212,7 +212,7 @@ "data" : [ [ "Perl", - 663 + 665 ], [ "Blog", @@ -276,11 +276,11 @@ "data" : [ [ "Perl", - 402 + 404 ], [ "Blog", - 194 + 195 ] ], "id" : "Peter Campbell Smith", @@ -318,11 +318,11 @@ "data" : [ [ "Perl", - 278 + 280 ], [ "Blog", - 271 + 273 ] ], "id" : "Thomas Kohler", @@ -646,7 +646,7 @@ "data" : [ [ "Perl", - 278 + 280 ] ], "id" : "Peter Meszaros", @@ -847,7 +847,7 @@ { "drilldown" : "W. Luis Mochan", "name" : "11: W. Luis Mochan", - "y" : 1486 + "y" : 1492 }, { "drilldown" : "Adam Russell", @@ -857,7 +857,7 @@ { "drilldown" : "E. Choroba", "name" : "13: E. Choroba", - "y" : 1440 + "y" : 1444 }, { "drilldown" : "Colin Crain", @@ -877,7 +877,7 @@ { "drilldown" : "Peter Campbell Smith", "name" : "17: Peter Campbell Smith", - "y" : 1192 + "y" : 1198 }, { "drilldown" : "Paulo Custodio", @@ -892,7 +892,7 @@ { "drilldown" : "Thomas Kohler", "name" : "20: Thomas Kohler", - "y" : 1098 + "y" : 1106 }, { "drilldown" : "Feng Chang", @@ -1002,7 +1002,7 @@ { "drilldown" : "Peter Meszaros", "name" : "42: Peter Meszaros", - "y" : 556 + "y" : 560 }, { "drilldown" : "Stephen G. Lynn", @@ -1049,7 +1049,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the score breakdown. Last updated at 2025-09-15 10:18:43 GMT" + "text" : "Click the columns to drilldown the score breakdown. Last updated at 2025-09-15 22:12:18 GMT" }, "title" : { "text" : "Team Leaders (TOP 50)" diff --git a/stats/pwc-summary-1-30.json b/stats/pwc-summary-1-30.json index e7a174e210..afd0e6da8e 100644 --- a/stats/pwc-summary-1-30.json +++ b/stats/pwc-summary-1-30.json @@ -28,7 +28,7 @@ 44, 13, 8, - 76, + 78, 22, 8, 1, @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-09-15 10:18:43 GMT" + "text" : "[Champions: 30] Last updated at 2025-09-15 22:12:18 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-121-150.json b/stats/pwc-summary-121-150.json index b5b9e01eb3..76397b70e7 100644 --- a/stats/pwc-summary-121-150.json +++ b/stats/pwc-summary-121-150.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-09-15 10:18:43 GMT" + "text" : "[Champions: 30] Last updated at 2025-09-15 22:12:18 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-151-180.json b/stats/pwc-summary-151-180.json index b43db302e5..d2ca771c43 100644 --- a/stats/pwc-summary-151-180.json +++ b/stats/pwc-summary-151-180.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-09-15 10:18:43 GMT" + "text" : "[Champions: 30] Last updated at 2025-09-15 22:12:18 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-181-210.json b/stats/pwc-summary-181-210.json index 71b90de85c..ad2c7d7d5b 100644 --- a/stats/pwc-summary-181-210.json +++ b/stats/pwc-summary-181-210.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-09-15 10:18:43 GMT" + "text" : "[Champions: 30] Last updated at 2025-09-15 22:12:18 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-211-240.json b/stats/pwc-summary-211-240.json index b0eae9a756..6a4663fbbe 100644 --- a/stats/pwc-summary-211-240.json +++ b/stats/pwc-summary-211-240.json @@ -26,9 +26,9 @@ 4, 180, 0, - 402, + 404, 1, - 278, + 280, 10, 11, 7, @@ -96,7 +96,7 @@ 0, 0, 0, - 194, + 195, 0, 0, 2, @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-09-15 10:18:43 GMT" + "text" : "[Champions: 30] Last updated at 2025-09-15 22:12:18 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-241-270.json b/stats/pwc-summary-241-270.json index 934035a903..2a177a4887 100644 --- a/stats/pwc-summary-241-270.json +++ b/stats/pwc-summary-241-270.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-09-15 10:18:43 GMT" + "text" : "[Champions: 30] Last updated at 2025-09-15 22:12:18 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-271-300.json b/stats/pwc-summary-271-300.json index 5abad7858a..85cc961ad4 100644 --- a/stats/pwc-summary-271-300.json +++ b/stats/pwc-summary-271-300.json @@ -38,7 +38,7 @@ 6, 4, 2, - 278, + 280, 1 ], "name" : "Perl" @@ -108,14 +108,14 @@ 0, 0, 0, - 271, + 273, 0 ], "name" : "Blog" } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-09-15 10:18:43 GMT" + "text" : "[Champions: 30] Last updated at 2025-09-15 22:12:18 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-301-330.json b/stats/pwc-summary-301-330.json index 664244f2eb..6773950136 100644 --- a/stats/pwc-summary-301-330.json +++ b/stats/pwc-summary-301-330.json @@ -28,7 +28,7 @@ 28, 0, 4, - 494, + 496, 87, 342, 1, @@ -94,7 +94,7 @@ 0, 0, 0, - 247, + 248, 18, 2, 0, @@ -109,7 +109,7 @@ } ], "subtitle" : { - "text" : "[Champions: 28] Last updated at 2025-09-15 10:18:43 GMT" + "text" : "[Champions: 28] Last updated at 2025-09-15 22:12:18 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-31-60.json b/stats/pwc-summary-31-60.json index c427f07223..a666628f7c 100644 --- a/stats/pwc-summary-31-60.json +++ b/stats/pwc-summary-31-60.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-09-15 10:18:43 GMT" + "text" : "[Champions: 30] Last updated at 2025-09-15 22:12:18 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-61-90.json b/stats/pwc-summary-61-90.json index 731fcf6d8a..2198cd7ebf 100644 --- a/stats/pwc-summary-61-90.json +++ b/stats/pwc-summary-61-90.json @@ -33,7 +33,7 @@ 0, 82, 396, - 663, + 665, 2, 5, 8, @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-09-15 10:18:43 GMT" + "text" : "[Champions: 30] Last updated at 2025-09-15 22:12:18 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-91-120.json b/stats/pwc-summary-91-120.json index 5038b7af82..648a1e5c3c 100644 --- a/stats/pwc-summary-91-120.json +++ b/stats/pwc-summary-91-120.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-09-15 10:18:43 GMT" + "text" : "[Champions: 30] Last updated at 2025-09-15 22:12:18 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary.json b/stats/pwc-summary.json index b8bb961d00..4da3f8bba5 100644 --- a/stats/pwc-summary.json +++ b/stats/pwc-summary.json @@ -28,7 +28,7 @@ 26, 9, 4, - 38, + 39, 11, 4, 1, @@ -93,7 +93,7 @@ 0, 43, 202, - 332, + 333, 1, 3, 4, @@ -236,9 +236,9 @@ 2, 102, 0, - 204, + 205, 1, - 139, + 140, 5, 10, 4, @@ -308,7 +308,7 @@ 3, 2, 1, - 141, + 142, 1, 6, 7, @@ -328,7 +328,7 @@ 19, 0, 2, - 247, + 248, 44, 181, 1, @@ -902,7 +902,7 @@ 0, 0, 0, - 192, + 193, 0, 0, 2, @@ -974,7 +974,7 @@ 0, 0, 0, - 138, + 139, 0, 3, 0, @@ -994,7 +994,7 @@ 0, 0, 0, - 247, + 248, 18, 1, 0, @@ -1009,7 +1009,7 @@ } ], "subtitle" : { - "text" : "[Champions: 328] Last updated at 2025-09-15 10:18:43 GMT" + "text" : "[Champions: 328] Last updated at 2025-09-15 22:12:18 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-yearly-language-summary.json b/stats/pwc-yearly-language-summary.json index d82ef0d0 |
