diff options
| author | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2024-10-20 23:49:04 +0100 |
|---|---|---|
| committer | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2024-10-20 23:49:04 +0100 |
| commit | c15019778096cdd03604ead1e83052acc51d0ca7 (patch) | |
| tree | 2908445341cd0d2d512a76189f610f3b4c736005 | |
| parent | 520cb5dc89e105c9ff67c2ca2ae08e4d9ae6a4f4 (diff) | |
| download | perlweeklychallenge-club-c15019778096cdd03604ead1e83052acc51d0ca7.tar.gz perlweeklychallenge-club-c15019778096cdd03604ead1e83052acc51d0ca7.tar.bz2 perlweeklychallenge-club-c15019778096cdd03604ead1e83052acc51d0ca7.zip | |
- Added blog post by Roger Bell_West.
- Added solutions by Simon Green.
- Added solutions by Cheok-Yin Fung.
- Added solutions by Paulo Custodio.
- Added solutions by Matthew Neleigh.
- Added solutions by Arne Sommer.
- Added solutions by BarrOff.
- Added solutions by Matthew Muth.
- Added solutions by Asher Harvey-Smith.
- Added solutions by Wanderdoc.
23 files changed, 3100 insertions, 2913 deletions
diff --git a/challenge-291/wanderdoc/perl/ch-1.pl b/challenge-291/wanderdoc/perl/ch-1.pl new file mode 100755 index 0000000000..492ed9391d --- /dev/null +++ b/challenge-291/wanderdoc/perl/ch-1.pl @@ -0,0 +1,66 @@ +#!perl
+use strict;
+use warnings FATAL => qw(all);
+
+=prompt
+You are given an array of integers, @ints.
+
+Write a script to find the leftmost middle index (MI) i.e. the smallest amongst all the possible ones.
+
+ A middle index is an index where ints[0] + ints[1] + ... + ints[MI-1] == ints[MI+1] + ints[MI+2] + ... + ints[ints.length-1].
+
+If MI == 0, the left side sum is considered to be 0. Similarly,
+if MI == ints.length - 1, the right side sum is considered to be 0.
+
+Return the leftmost MI that satisfies the condition, or -1 if there is no such index.
+Example 1
+
+Input: @ints = (2, 3, -1, 8, 4)
+Output: 3
+
+The sum of the numbers before index 3 is: 2 + 3 + -1 = 4
+The sum of the numbers after index 3 is: 4 = 4
+
+Example 2
+
+Input: @ints = (1, -1, 4)
+Output: 2
+
+The sum of the numbers before index 2 is: 1 + -1 = 0
+The sum of the numbers after index 2 is: 0
+
+Example 3
+
+Input: @ints = (2, 5)
+Output: -1
+
+There is no valid MI.
+=cut
+
+
+use List::Util qw(sum);
+use Test2::V0;
+
+is(middle_index(2, 3, -1, 8, 4), 3, 'Example 1');
+is(middle_index(1, -1, 4), 2, 'Example 2');
+is(middle_index(2, 5), -1, 'Example 3');
+done_testing();
+
+
+sub middle_index
+{
+ my @arr = @_;
+ for my $idx ( 0 .. $#arr )
+ {
+ my ($sum_left, $sum_right);
+ if ( $idx == 0 ) { $sum_left = 0; $sum_right = sum(@arr[1 .. $#arr]); }
+ elsif ( $idx == $#arr ) { $sum_left = sum(@arr[0 .. $#arr - 1]); $sum_right = 0; }
+ else
+ {
+ $sum_left = sum(@arr[0 .. $idx - 1]);
+ $sum_right = sum(@arr[$idx + 1 .. $#arr]);
+ }
+ if ( $sum_left == $sum_right ) { return $idx; }
+ }
+ return -1;
+}
\ No newline at end of file diff --git a/stats/pwc-current.json b/stats/pwc-current.json index e516250c69..b0af67da57 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,190 +1,109 @@ { + "title" : { + "text" : "The Weekly Challenge - 291" + }, + "subtitle" : { + "text" : "[Champions: 34] Last updated at 2024-10-20 22:48:52 GMT" + }, "plotOptions" : { "series" : { + "borderWidth" : 0, "dataLabels" : { - "format" : "{point.y}", - "enabled" : 1 - }, - "borderWidth" : 0 + "enabled" : 1, + "format" : "{point.y}" + } } }, - "series" : [ - { - "colorByPoint" : 1, - "data" : [ - { - "y" : 4, - "drilldown" : "Athanasius", - "name" : "Athanasius" - }, - { - "y" : 2, - "drilldown" : "Bob Lied", - "name" : "Bob Lied" - }, - { - "y" : 3, - "drilldown" : "Dave Jacoby", - "name" : "Dave Jacoby" - }, - { - "y" : 2, - "name" : "David Ferrone", - "drilldown" : "David Ferrone" - }, - { - "drilldown" : "E. Choroba", - "name" : "E. Choroba", - "y" : 2 - }, - { - "name" : "Feng Chang", - "drilldown" : "Feng Chang", - "y" : 2 - }, - { - "y" : 2, - "name" : "Jan Krnavek", - "drilldown" : "Jan Krnavek" - }, - { - "drilldown" : "Kjetil Skotheim", - "name" : "Kjetil Skotheim", - "y" : 2 - }, - { - "name" : "Laurent Rosenfeld", - "drilldown" : "Laurent Rosenfeld", - "y" : 6 - }, - { - "drilldown" : "Lubos Kolouch", - "name" : "Lubos Kolouch", - "y" : 2 - }, - { - "name" : "Mark Anderson", - "drilldown" : "Mark Anderson", - "y" : 2 - }, - { - "name" : "Matthew Neleigh", - "drilldown" : "Matthew Neleigh", - "y" : 2 - }, - { - "name" : "Packy Anderson", - "drilldown" : "Packy Anderson", - "y" : 5 - }, - { - "y" : 1, - "drilldown" : "Paulo Custodio", - "name" : "Paulo Custodio" - }, - { - "y" : 2, - "drilldown" : "Pawel Kuciel", - "name" : "Pawel Kuciel" - }, - { - "y" : 3, - "name" : "Peter Campbell Smith", - "drilldown" : "Peter Campbell Smith" - }, - { - "y" : 2, - "name" : "Peter Meszaros", - "drilldown" : "Peter Meszaros" - }, - { - "y" : 2, - "drilldown" : "Reinier Maliepaard", - "name" : "Reinier Maliepaard" - }, - { - "drilldown" : "Robbie Hatley", - "name" : "Robbie Hatley", - "y" : 3 - }, - { - "y" : 2, - "name" : "Robert Ransbottom", - "drilldown" : "Robert Ransbottom" - }, - { - "name" : "Roger Bell_West", - "drilldown" : "Roger Bell_West", - "y" : 4 - }, - { - "drilldown" : "Santiago Leyva", - "name" : "Santiago Leyva", - "y" : 2 - }, - { - "y" : 2, - "drilldown" : "Thomas Kohler", - "name" : "Thomas Kohler" - }, - { - "drilldown" : "Tim King", - "name" : "Tim King", - "y" : 2 - }, - { - "y" : 2, - "name" : "Tomasz Mucha", - "drilldown" : "Tomasz Mucha" - }, - { - "drilldown" : "Ulrich Rieke", - "name" : "Ulrich Rieke", - "y" : 4 - }, - { - "name" : "W. Luis Mochan", - "drilldown" : "W. Luis Mochan", - "y" : 3 - } - ], - "name" : "The Weekly Challenge - 291" - } - ], "xAxis" : { "type" : "category" }, - "title" : { - "text" : "The Weekly Challenge - 291" + "tooltip" : { + "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>", + "followPointer" : 1, + "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>" + }, + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } + }, + "legend" : { + "enabled" : 0 + }, + "chart" : { + "type" : "column" }, "drilldown" : { "series" : [ { + "id" : "Arne Sommer", "data" : [ [ - "Perl", + "Raku", 2 ], [ + "Blog", + 1 + ] + ], + "name" : "Arne Sommer" + }, + { + "data" : [ + [ "Raku", 2 ] ], - "name" : "Athanasius", - "id" : "Athanasius" + "name" : "Asher Harvey-Smith", + "id" : "Asher Harvey-Smith" }, { + "name" : "Athanasius", "data" : [ [ "Perl", 2 + ], + [ + "Raku", + 2 + ] + ], + "id" : "Athanasius" + }, + { + "name" : "BarrOff", + "data" : [ + [ + "Raku", + 1 ] ], + "id" : "BarrOff" + }, + { + "id" : "Bob Lied", "name" : "Bob Lied", - "id" : "Bob Lied" + "data" : [ + [ + "Perl", + 2 + ] + ] + }, + { + "id" : "Cheok-Yin Fung", + "name" : "Cheok-Yin Fung", + "data" : [ + [ + "Perl", + 1 + ] + ] }, { - "id" : "Dave Jacoby", "data" : [ [ "Perl", @@ -195,7 +114,8 @@ 1 ] ], - "name" : "Dave Jacoby" + "name" : "Dave Jacoby", + "id" : "Dave Jacoby" }, { "id" : "David Ferrone", @@ -208,46 +128,48 @@ "name" : "David Ferrone" }, { + "id" : "E. Choroba", "data" : [ [ "Perl", 2 ] ], - "name" : "E. Choroba", - "id" : "E. Choroba" + "name" : "E. Choroba" }, { - "id" : "Feng Chang", "data" : [ [ "Raku", 2 ] ], - "name" : "Feng Chang" + "name" : "Feng Chang", + "id" : "Feng Chang" }, { - "id" : "Jan Krnavek", "data" : [ [ "Raku", 2 ] ], - "name" : "Jan Krnavek" + "name" : "Jan Krnavek", + "id" : "Jan Krnavek" }, { + "name" : "Kjetil Skotheim", "data" : [ [ "Perl", 2 ] ], - "name" : "Kjetil Skotheim", "id" : "Kjetil Skotheim" }, { + "id" : "Laurent Rosenfeld", + "name" : "Laurent Rosenfeld", "data" : [ [ "Perl", @@ -261,43 +183,53 @@ "Blog", 2 ] - ], - "name" : "Laurent Rosenfeld", - "id" : "Laurent Rosenfeld" + ] }, { - "id" : "Lubos Kolouch", + "name" : "Lubos Kolouch", "data" : [ [ "Perl", 2 ] ], - "name" : "Lubos Kolouch" + "id" : "Lubos Kolouch" }, { - "id" : "Mark Anderson", "name" : "Mark Anderson", "data" : [ [ "Raku", 2 ] - ] + ], + "id" : "Mark Anderson" }, { - "name" : "Matthew Neleigh", "data" : [ [ "Perl", 2 ] ], + "name" : "Matthew Neleigh", "id" : "Matthew Neleigh" }, { - "id" : "Packy Anderson", - "name" : "Packy Anderson", + "id" : "Matthias Muth", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "name" : "Matthias Muth" + }, + { "data" : [ [ "Perl", @@ -311,27 +243,29 @@ "Blog", 1 ] - ] + ], + "name" : "Packy Anderson", + "id" : "Packy Anderson" }, { "id" : "Paulo Custodio", - "name" : "Paulo Custodio", "data" : [ [ "Perl", - 1 + 2 ] - ] + ], + "name" : "Paulo Custodio" }, { - "name" : "Pawel Kuciel", + "id" : "Pawel Kuciel", "data" : [ [ "Perl", 2 ] ], - "id" : "Pawel Kuciel" + "name" : "Pawel Kuciel" }, { "id" : "Peter Campbell Smith", @@ -372,7 +306,7 @@ "id" : "Reinier Maliepaard" }, { - "id" : "Robbie Hatley", + "name" : "Robbie Hatley", "data" : [ [ "Perl", @@ -383,19 +317,20 @@ 1 ] ], - "name" : "Robbie Hatley" + "id" : "Robbie Hatley" }, { + "id" : "Robert Ransbottom", "name" : "Robert Ransbottom", "data" : [ [ "Raku", 2 ] - ], - "id" : "Robert Ransbottom" + ] }, { + "id" : "Roger Bell_West", "name" : "Roger Bell_West", "data" : [ [ @@ -405,21 +340,25 @@ [ "Raku", 2 + ], + [ + "Blog", + 1 ] - ], - "id" : "Roger Bell_West" + ] }, { "id" : "Santiago Leyva", - "name" : "Santiago Leyva", "data" : [ [ "Perl", 2 ] - ] + ], + "name" : "Santiago Leyva" }, { + "id" : "Simon Green", "data" : [ [ "Perl", @@ -430,11 +369,24 @@ 1 ] ], + "name" : "Simon Green" + }, + { + "id" : "Thomas Kohler", "name" : "Thomas Kohler", - "id" : "Thomas Kohler" + "data" : [ + [ + "Perl", + 1 + ], + [ + "Blog", + 1 + ] + ] }, { - "name" : "Tim King", + "id" : "Tim King", "data" : [ [ "Perl", @@ -445,19 +397,20 @@ 1 ] ], - "id" : "Tim King" + "name" : "Tim King" }, { "id" : "Tomasz Mucha", - "name" : "Tomasz Mucha", "data" : [ [ "Perl", 2 ] - ] + ], + "name" : "Tomasz Mucha" }, { + "name" : "Ulrich Rieke", "data" : [ [ "Perl", @@ -468,11 +421,9 @@ 2 ] ], - "name" : "Ulrich Rieke", "id" : "Ulrich Rieke" }, { - "name" : "W. Luis Mochan", "data" : [ [ "Perl", @@ -483,27 +434,197 @@ 1 ] ], + "name" : "W. Luis Mochan", "id" : "W. Luis Mochan" + }, + { + "id" : "Wanderdoc", + "name" : "Wanderdoc", + "data" : [ + [ + "Perl", + 1 + ] + ] } ] }, - "legend" : { - "enabled" : 0 - }, - "subtitle" : { - "text" : "[Champions: 27] Last updated at 2024-10-20 10:53:09 GMT" - }, - "yAxis" : { - "title" : { - "text" : "Total Solutions" + "series" : [ + { + "colorByPoint" : 1, + "name" : "The Weekly Challenge - 291", + "data" : [ + { + "drilldown" : "Arne Sommer", + "name" : "Arne Sommer", + "y" : 3 + }, + { + "drilldown" : "Asher Harvey-Smith", + "name" : "Asher Harvey-Smith", + "y" : 2 + }, + { + "y" : 4, + "name" : "Athanasius", + "drilldown" : "Athanasius" + }, + { + "name" : "BarrOff", + "y" : 1, + "drilldown" : "BarrOff" + }, + { + "name" : "Bob Lied", + "y" : 2, + "drilldown" : "Bob Lied" + }, + { + "drilldown" : "Cheok-Yin Fung", + "y" : 1, + "name" : "Cheok-Yin Fung" + }, + { + "y" : 3, + "name" : "Dave Jacoby", + "drilldown" : "Dave Jacoby" + }, + { + "name" : "David Ferrone", + "y" : 2, + "drilldown" : "David Ferrone" + }, + { + "y" : 2, + "name" : "E. Choroba", + "drilldown" : "E. Choroba" + }, + { + "name" : "Feng Chang", + "y" : 2, + "drilldown" : "Feng Chang" + }, + { + "drilldown" : "Jan Krnavek", + "y" : 2, + "name" : "Jan Krnavek" + }, + { + "name" : "Kjetil Skotheim", + "y" : 2, + "drilldown" : "Kjetil Skotheim" + }, + { + "drilldown" : "Laurent Rosenfeld", + "y" : 6, + "name" : "Laurent Rosenfeld" + }, + { + "drilldown" : "Lubos Kolouch", + "name" : "Lubos Kolouch", + "y" : 2 + }, + { + "name" : "Mark Anderson", + "y" : 2, + "drilldown" : "Mark Anderson" + }, + { + "y" : 2, + "name" : "Matthew Neleigh", + "drilldown" : "Matthew Neleigh" + }, + { + "drilldown" : "Matthias Muth", + "y" : 3, + "name" : "Matthias Muth" + }, + { + "drilldown" : "Packy Anderson", + "name" : "Packy Anderson", + "y" : 5 + }, + { + "y" : 2, + "name" : "Paulo Custodio", + "drilldown" : "Paulo Custodio" + }, + { + "name" : "Pawel Kuciel", + "y" : 2, + "drilldown" : "Pawel Kuciel" + }, + { + "drilldown" : "Peter Campbell Smith", + "name" : "Peter Campbell Smith", + "y" : 3 + }, + { + "name" : "Peter Meszaros", + "y" : 2, + "drilldown" : "Peter Meszaros" + }, + { + "drilldown" : "Reinier Maliepaard", + "name" : "Reinier Maliepaard", + "y" : 2 + }, + { + "drilldown" : "Robbie Hatley", + "y" : 3, + "name" : "Robbie Hatley" + }, + { + "drilldown" : "Robert Ransbottom", + "name" : "Robert Ransbottom", + "y" : 2 + }, + { + "drilldown" : "Roger Bell_West", + "name" : "Roger Bell_West", + "y" : 5 + }, + { + "drilldown" : "Santiago Leyva", + "y" : 2, + "name" : "Santiago Leyva" + }, + { + "drilldown" : "Simon Green", + "name" : "Simon Green", + "y" : 2 + }, + { + "name" : "Thomas Kohler", + "y" : 2, + "drilldown" : "Thomas Kohler" + }, + { + "name" : "Tim King", + "y" : 2, + "drilldown" : "Tim King" + }, + { + "name" : "Tomasz Mucha", + "y" : 2, + "drilldown" : "Tomasz Mucha" + }, + { + "name" : "Ulrich Rieke", + "y" : 4, + "drilldown" : "Ulrich Rieke" + }, + { + "y" : 3, + "name" : "W. Luis Mochan", + "drilldown" : "W. Luis Mochan" + }, + { + "drilldown" : "Wanderdoc", + "name" : "Wanderdoc", + "y" : 1 + } + ] } - }, - "tooltip" : { - "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>", - "followPointer" : 1, - "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>" - }, - "chart" : { - "type" : "column" - } + ] } diff --git a/stats/pwc-language-breakdown-2019.json b/stats/pwc-language-breakdown-2019.json index ccdeea6405..a6b954c80b 100644 --- a/stats/pwc-language-breakdown-2019.json +++ b/stats/pwc-language-breakdown-2019.json @@ -1,25 +1,41 @@ { - "tooltip" : { - "followPointer" : "true", - "headerFormat" : "<span style=\"font-size:11px\"></span>", - "pointFormat" : "<span style=\"color:{point.color}\">Challenge {point.name}</span>: <b>{point.y:f}</b><br/>" + "title" : { + "text" : "The Weekly Challenge Language" + }, + "subtitle" : { + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2024-10-20 22:48:52 GMT" + }, + "plotOptions" : { + "series" : { + "dataLabels" : { + "enabled" : 1, + "format" : "{point.y}" + }, + "borderWidth" : 0 + } + }, + "legend" : { + "enabled" : "false" }, "chart" : { "type" : "column" }, - "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2024-10-20 10:53:09 GMT" - }, "yAxis" : { "title" : { "text" : "Total Solutions" } }, + "tooltip" : { + "pointFormat" : "<span style=\"color:{point.color}\">Challenge {point.name}</span>: <b>{point.y:f}</b><br/>", + "headerFormat" : "<span style=\"font-size:11px\"></span>", + "followPointer" : "true" + }, + "xAxis" : { + "type" : "category" + }, "drilldown" : { "series" : [ { - "id" : "041", - "name" : "041", "data" : [ [ "Perl", @@ -33,10 +49,11 @@ "Blog", 9 ] - ] + ], + "name" : "041", + "id" : "041" }, { - "id" : "040", "name" : "040", "data" : [ [ @@ -51,10 +68,12 @@ "Blog", 10 ] - ] + ], + "id" : "040" }, { "id" : "039", + "name" : "039", "data" : [ [ "Perl", @@ -68,11 +87,9 @@ "Blog", 12 ] - ], - "name" : "039" + ] }, { - "id" : "038", "name" : "038", "data" : [ [ @@ -87,9 +104,12 @@ "Blog", 12 ] - ] + ], + "id" : "038" }, { + "id" : "037", + "name" : "037", "data" : [ [ "Perl", @@ -103,9 +123,7 @@ "Blog", 9 ] - ], - "name" : "037", - "id" : "037" + ] }, { "id" : "036", @@ -126,7 +144,6 @@ ] }, { - "name" : "035", "data" : [ [ "Perl", @@ -141,10 +158,11 @@ 9 ] ], + "name" : "035", "id" : "035" }, { - "id" : "034", + "name" : "034", "data" : [ [ "Perl", @@ -159,7 +177,7 @@ 11 ] ], - "name" : "034" + "id" : "034" }, { "data" : [ @@ -181,7 +199,6 @@ }, { "id" : "032", - "name |
