diff options
| -rw-r--r-- | challenge-218/laurent-rosenfeld/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-218/laurent-rosenfeld/perl/ch-1.pl | 30 | ||||
| -rw-r--r-- | challenge-218/laurent-rosenfeld/raku/ch-1.raku | 21 | ||||
| -rw-r--r-- | challenge-218/laurent-rosenfeld/raku/ch-2.raku | 26 | ||||
| -rw-r--r-- | stats/pwc-current.json | 269 | ||||
| -rw-r--r-- | stats/pwc-language-breakdown-summary.json | 72 | ||||
| -rw-r--r-- | stats/pwc-language-breakdown.json | 1476 | ||||
| -rw-r--r-- | stats/pwc-leaders.json | 730 | ||||
| -rw-r--r-- | stats/pwc-summary-1-30.json | 38 | ||||
| -rw-r--r-- | stats/pwc-summary-121-150.json | 112 | ||||
| -rw-r--r-- | stats/pwc-summary-151-180.json | 102 | ||||
| -rw-r--r-- | stats/pwc-summary-181-210.json | 44 | ||||
| -rw-r--r-- | stats/pwc-summary-211-240.json | 94 | ||||
| -rw-r--r-- | stats/pwc-summary-241-270.json | 24 | ||||
| -rw-r--r-- | stats/pwc-summary-271-300.json | 46 | ||||
| -rw-r--r-- | stats/pwc-summary-31-60.json | 126 | ||||
| -rw-r--r-- | stats/pwc-summary-61-90.json | 46 | ||||
| -rw-r--r-- | stats/pwc-summary-91-120.json | 92 | ||||
| -rw-r--r-- | stats/pwc-summary.json | 44 |
19 files changed, 1747 insertions, 1646 deletions
diff --git a/challenge-218/laurent-rosenfeld/blog.txt b/challenge-218/laurent-rosenfeld/blog.txt new file mode 100644 index 0000000000..46f2c748b3 --- /dev/null +++ b/challenge-218/laurent-rosenfeld/blog.txt @@ -0,0 +1 @@ +https://blogs.perl.org/users/laurent_r/2023/05/perl-weekly-challenge-218-maximum-product-and-matrix-score.html diff --git a/challenge-218/laurent-rosenfeld/perl/ch-1.pl b/challenge-218/laurent-rosenfeld/perl/ch-1.pl new file mode 100644 index 0000000000..7b5306082a --- /dev/null +++ b/challenge-218/laurent-rosenfeld/perl/ch-1.pl @@ -0,0 +1,30 @@ +use strict; +use warnings; +use feature 'say'; + +sub prod { + my $prod = shift; + $prod *= $_ for @_; + return $prod; +} + +sub max_prod { + my @list = sort { abs($b) <=> abs($a) } @_; + return prod @list[0..2] if 0 < prod @list[0..2]; + # brute force if we get here + my $max = $_[0]; + for my $i (0..$#list) { + for my $j ($i+1..$#list) { + for my $k ($j+1..$#list) { + my $prod = $list[$i] * $list[$j] * $list[$k]; + $max = $prod if $prod > $max; + } + } + } + return $max; +} +for my $test ([3, 1, 2], [4, 1, 3, 2], [-1, 0, 1, 3, 1], + [-8, 2, -9, 0, -4, 3], [-8, 2, 3, 5, 6]) { + printf "%-15s => ", "@$test"; + say max_prod @$test; +} diff --git a/challenge-218/laurent-rosenfeld/raku/ch-1.raku b/challenge-218/laurent-rosenfeld/raku/ch-1.raku new file mode 100644 index 0000000000..39e5f25635 --- /dev/null +++ b/challenge-218/laurent-rosenfeld/raku/ch-1.raku @@ -0,0 +1,21 @@ +sub max-prod (@in) { + my @list = reverse sort { .abs }, @in; + return [*] @list[0..2] if @list[0..2].all > 0 + or @list[0..2].one > 0; + if @list[0..2].all < 0 { + # find first positive value to replace one neg + my $first = @list[3..@list.end].first({ $_ > 0}); + return [*] (@list[0..1], $first).flat if $first.defined; + } + # brute force if we get here + my @comb-prods = gather { + for @list.combinations: 3 -> @comb { + take [*] @comb; + } + } + return @comb-prods.max; +} +for (3, 1, 2), (4, 1, 3, 2), (-1, 0, 1, 3, 1), + (-8, 2, -9, 0, -4, 3), (-8, 2, 3, 5, 6) -> @test { + say "@test[]".fmt("%-15s => "), max-prod @test; +} diff --git a/challenge-218/laurent-rosenfeld/raku/ch-2.raku b/challenge-218/laurent-rosenfeld/raku/ch-2.raku new file mode 100644 index 0000000000..522922c873 --- /dev/null +++ b/challenge-218/laurent-rosenfeld/raku/ch-2.raku @@ -0,0 +1,26 @@ +sub toggle_col (@in, $i) { + for 0..@in.end -> $j { + @in[$j][$i] = +not @in[$j][$i]; + } +} +sub improve-score (@in) { + my $col-max = @in.elems - 1; + my $row-max = @in[0].elems - 1; + for @in -> @row { + if @row[0] == 0 { + $_ = +not $_ for @row; + } + } + for 0..$row-max -> $index { + my @col; + push @col, @in[$_][$index] for 0..$col-max; + toggle_col(@in, $index) if @in.elems/2 > [+] @col; + } + return @in; +} + +my @test = [0,0,1,1], [1,0,1,0], [1,1,0,0]; +say "Test: ", @test; +my @new-mat = improve-score @test; +say "Result: ", @new-mat; +say "Score: ", [+] map {$_.join('').parse-base(2)}, @new-mat; diff --git a/stats/pwc-current.json b/stats/pwc-current.json index b043dea73b..bfa4903fb6 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,16 +1,17 @@ { "series" : [ { + "name" : "The Weekly Challenge - 218", "data" : [ { + "y" : 3, "drilldown" : "Arne Sommer", - "name" : "Arne Sommer", - "y" : 3 + "name" : "Arne Sommer" }, { - "name" : "Athanasius", "y" : 2, - "drilldown" : "Athanasius" + "drilldown" : "Athanasius", + "name" : "Athanasius" }, { "drilldown" : "Avery Adams", @@ -19,8 +20,8 @@ }, { "name" : "BarrOff", - "y" : 2, - "drilldown" : "BarrOff" + "drilldown" : "BarrOff", + "y" : 2 }, { "drilldown" : "Bruce Gray", @@ -28,29 +29,29 @@ "name" : "Bruce Gray" }, { + "name" : "Cheok-Yin Fung", "drilldown" : "Cheok-Yin Fung", - "y" : 2, - "name" : "Cheok-Yin Fung" + "y" : 2 }, { - "name" : "David Ferrone", + "drilldown" : "David Ferrone", "y" : 2, - "drilldown" : "David Ferrone" + "name" : "David Ferrone" }, { + "name" : "E. Choroba", "drilldown" : "E. Choroba", - "y" : 2, - "name" : "E. Choroba" + "y" : 2 }, { - "y" : 6, "name" : "Flavio Poletti", - "drilldown" : "Flavio Poletti" + "drilldown" : "Flavio Poletti", + "y" : 6 }, { + "name" : "Jaldhar H. Vyas", "drilldown" : "Jaldhar H. Vyas", - "y" : 5, - "name" : "Jaldhar H. Vyas" + "y" : 5 }, { "drilldown" : "Jan Krnavek", @@ -59,33 +60,38 @@ }, { "y" : 2, - "name" : "Jorg Sommrey", - "drilldown" : "Jorg Sommrey" + "drilldown" : "Jorg Sommrey", + "name" : "Jorg Sommrey" + }, + { + "y" : 4, + "drilldown" : "Laurent Rosenfeld", + "name" : "Laurent Rosenfeld" }, { - "y" : 2, "name" : "Lubos Kolouch", + "y" : 2, "drilldown" : "Lubos Kolouch" }, { + "name" : "Mark Anderson", "drilldown" : "Mark Anderson", - "y" : 2, - "name" : "Mark Anderson" + "y" : 2 }, { "drilldown" : "Matthias Muth", - "name" : "Matthias Muth", - "y" : 3 + "y" : 3, + "name" : "Matthias Muth" }, { - "drilldown" : "Niels van Dijke", + "name" : "Niels van Dijke", "y" : 2, - "name" : "Niels van Dijke" + "drilldown" : "Niels van Dijke" }, { "name" : "Paulo Custodio", - "y" : 2, - "drilldown" : "Paulo Custodio" + "drilldown" : "Paulo Custodio", + "y" : 2 }, { "drilldown" : "Peter Campbell Smith", @@ -93,53 +99,53 @@ "name" : "Peter Campbell Smith" }, { - "name" : "Robbie Hatley", "y" : 2, - "drilldown" : "Robbie Hatley" + "drilldown" : "Robbie Hatley", + "name" : "Robbie Hatley" }, { - "name" : "Robert DiCicco", "y" : 4, - "drilldown" : "Robert DiCicco" + "drilldown" : "Robert DiCicco", + "name" : "Robert DiCicco" }, { - "drilldown" : "Robert Ransbottom", "y" : 2, + "drilldown" : "Robert Ransbottom", "name" : "Robert Ransbottom" }, { "drilldown" : "Roger Bell_West", - "name" : "Roger Bell_West", - "y" : 5 + "y" : 5, + "name" : "Roger Bell_West" }, { - "drilldown" : "Simon Green", + "name" : "Simon Green", "y" : 3, - "name" : "Simon Green" + "drilldown" : "Simon Green" }, { - "name" : "Solathian", + "drilldown" : "Solathian", "y" : 1, - "drilldown" : "Solathian" + "name" : "Solathian" }, { - "name" : "Stephen G. Lynn", "y" : 3, - "drilldown" : "Stephen G. Lynn" + "drilldown" : "Stephen G. Lynn", + "name" : "Stephen G. Lynn" }, { + "name" : "Steven Wilson", "drilldown" : "Steven Wilson", - "y" : 1, - "name" : "Steven Wilson" + "y" : 1 }, { - "y" : 4, "name" : "Thomas Kohler", - "drilldown" : "Thomas Kohler" + "drilldown" : "Thomas Kohler", + "y" : 4 }, { - "drilldown" : "Ulrich Rieke", "y" : 3, + "drilldown" : "Ulrich Rieke", "name" : "Ulrich Rieke" }, { @@ -148,26 +154,14 @@ "drilldown" : "W. Luis Mochan" } ], - "name" : "The Weekly Challenge - 218", "colorByPoint" : 1 } ], - "xAxis" : { - "type" : "category" - }, - "yAxis" : { - "title" : { - "text" : "Total Solutions" - } - }, - "tooltip" : { - "followPointer" : 1, - "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>", - "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>" - }, "drilldown" : { "series" : [ { + "name" : "Arne Sommer", + "id" : "Arne Sommer", "data" : [ [ "Raku", @@ -177,13 +171,9 @@ "Blog", 1 ] - ], - "id" : "Arne Sommer", - "name" : "Arne Sommer" + ] }, { - "name" : "Athanasius", - "id" : "Athanasius", "data" : [ [ "Perl", @@ -193,11 +183,12 @@ "Raku", 1 ] - ] + ], + "id" : "Athanasius", + "name" : "Athanasius" }, { "name" : "Avery Adams", - "id" : "Avery Adams", "data" : [ [ "Perl", @@ -207,10 +198,10 @@ "Blog", 2 ] - ] + ], + "id" : "Avery Adams" }, { - "id" : "BarrOff", "name" : "BarrOff", "data" : [ [ @@ -221,27 +212,28 @@ "Raku", 1 ] - ] + ], + "id" : "BarrOff" }, { + "name" : "Bruce Gray", + "id" : "Bruce Gray", "data" : [ [ "Raku", 2 ] - ], - "id" : "Bruce Gray", - "name" : "Bruce Gray" + ] }, { - "id" : "Cheok-Yin Fung", "name" : "Cheok-Yin Fung", "data" : [ [ "Perl", 2 ] - ] + ], + "id" : "Cheok-Yin Fung" }, { "data" : [ @@ -250,22 +242,20 @@ 2 ] ], - "name" : "David Ferrone", - "id" : "David Ferrone" + "id" : "David Ferrone", + "name" : "David Ferrone" }, { - "name" : "E. Choroba", - "id" : "E. Choroba", "data" : [ [ "Perl", 2 ] - ] + ], + "id" : "E. Choroba", + "name" : "E. Choroba" }, { - "id" : "Flavio Poletti", - "name" : "Flavio Poletti", "data" : [ [ "Perl", @@ -279,9 +269,12 @@ "Blog", 2 ] - ] + ], + "id" : "Flavio Poletti", + "name" : "Flavio Poletti" }, { + "id" : "Jaldhar H. Vyas", "data" : [ [ "Perl", @@ -296,32 +289,49 @@ 1 ] ], - "id" : "Jaldhar H. Vyas", "name" : "Jaldhar H. Vyas" }, { "name" : "Jan Krnavek", - "id" : "Jan Krnavek", "data" : [ [ "Raku", 1 ] - ] + ], + "id" : "Jan Krnavek" }, { "name" : "Jorg Sommrey", - "id" : "Jorg Sommrey", "data" : [ [ "Perl", 2 ] + ], + "id" : "Jorg Sommrey" + }, + { + "name" : "Laurent Rosenfeld", + "id" : "Laurent Rosenfeld", + "data" : [ + [ + "Perl", + 1 + ], + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] ] }, { - "id" : "Lubos Kolouch", "name" : "Lubos Kolouch", + "id" : "Lubos Kolouch", "data" : [ [ "Perl", @@ -331,15 +341,16 @@ }, { "id" : "Mark Anderson", - "name" : "Mark Anderson", "data" : [ [ "Raku", 2 ] - ] + ], + "name" : "Mark Anderson" }, { + "name" : "Matthias Muth", "data" : [ [ "Perl", @@ -350,17 +361,16 @@ 1 ] ], - "name" : "Matthias Muth", "id" : "Matthias Muth" }, { + "id" : "Niels van Dijke", "data" : [ [ "Perl", 2 ] ], - "id" : "Niels van Dijke", "name" : "Niels van Dijke" }, { @@ -374,8 +384,6 @@ ] }, { - "name" : "Peter Campbell Smith", - "id" : "Peter Campbell Smith", "data" : [ [ "Perl", @@ -385,9 +393,12 @@ "Blog", 1 ] - ] + ], + "id" : "Peter Campbell Smith", + "name" : "Peter Campbell Smith" }, { + "id" : "Robbie Hatley", "data" : [ [ "Perl", @@ -398,12 +409,9 @@ 1 ] ], - "id" : "Robbie Hatley", "name" : "Robbie Hatley" }, { - "name" : "Robert DiCicco", - "id" : "Robert DiCicco", "data" : [ [ "Perl", @@ -413,11 +421,13 @@ "Raku", 2 ] - ] + ], + "id" : "Robert DiCicco", + "name" : "Robert DiCicco" }, { - "id" : "Robert Ransbottom", "name" : "Robert Ransbottom", + "id" : "Robert Ransbottom", "data" : [ [ "Raku", @@ -426,8 +436,6 @@ ] }, { - "id" : "Roger Bell_West", - "name" : "Roger Bell_West", "data" : [ [ "Perl", @@ -441,11 +449,12 @@ "Blog", 1 ] - ] + ], + "id" : "Roger Bell_West", + "name" : "Roger Bell_West" }, { "name" : "Simon Green", - "id" : "Simon Green", "data" : [ [ "Perl", @@ -455,20 +464,20 @@ "Blog", 1 ] - ] + ], + "id" : "Simon Green" }, { "name" : "Solathian", - "id" : "Solathian", "data" : [ [ "Perl", 1 ] - ] + ], + "id" : "Solathian" }, { - "id" : "Stephen G. Lynn", "name" : "Stephen G. Lynn", "data" : [ [ @@ -479,19 +488,21 @@ "Blog", 1 ] - ] + ], + "id" : "Stephen G. Lynn" }, { - "name" : "Steven Wilson", "id" : "Steven Wilson", "data" : [ [ "Perl", 1 ] - ] + ], + "name" : "Steven Wilson" }, { + "name" : "Thomas Kohler", "data" : [ [ "Perl", @@ -502,8 +513,7 @@ 2 ] ], - "id" : "Thomas Kohler", - "name" : "Thomas Kohler" + "id" : "Thomas Kohler" }, { "data" : [ @@ -520,6 +530,8 @@ "name" : "Ulrich Rieke" }, { + "name" : "W. Luis Mochan", + "id" : "W. Luis Mochan", "data" : [ [ "Perl", @@ -529,31 +541,42 @@ "Blog", 1 ] - ], - "name" : "W. Luis Mochan", - "id" : "W. Luis Mochan" + ] } ] }, "subtitle" : { - "text" : "[Champions: 29] Last updated at 2023-05-29 03:18:17 GMT" - }, - "legend" : { - "enabled" : 0 + "text" : "[Champions: 30] Last updated at 2023-05-30 08:44:43 GMT" }, "title" : { "text" : "The Weekly Challenge - 218" }, + "xAxis" : { + "type" : "category" + }, + "tooltip" : { + "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>", + "followPointer" : 1, + "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>" + }, + "chart" : { + "type" : "column" + }, + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } + }, "plotOptions" : { "series" : { "dataLabels" : { - "enabled" : 1, - "format" : "{point.y}" + "format" : "{point.y}", + "enabled" : 1 }, "borderWidth" : 0 } }, - "chart" : { - "type" : "column" + "legend" : { + "enabled" : 0 } } diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index 9c7235fbbf..b5c20e4055 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -1,63 +1,63 @@ { + "chart" : { + "type" : "column" + }, + "yAxis" : { + "min" : 0, + "title" : { + "text" : null + } + }, + "tooltip" : { + "pointFormat" : "<b>{point.y:.0f}</b>" + }, + "title" : { + "text" : "The Weekly Challenge Contributions [2019 - 2023]" + }, + "subtitle" : { + "text" : "Last updated at 2023-05-30 08:44:43 GMT" + }, + "xAxis" : { + "labels" : { + "style" : { + "fontFamily" : "Verdana, sans-serif", + "fontSize" : "13px" + } + }, + "type" : "category" + }, "series" : [ { "data" : [ [ "Blog", - 3611 + 3612 ], [ "Perl", - 11152 + 11153 ], [ "Raku", - 6441 + 6443 ] ], "dataLabels" : { - "color" : "#FFFFFF", "rotation" : -90, "format" : "{point.y:.0f}", - "y" : 10, - "align" : "right", "style" : { - "fontFamily" : "Verdana, sans-serif", - "fontSize" : "13px" + "fontSize" : "13px", + "fontFamily" : "Verdana, sans-serif" }, - "enabled" : "true" + "enabled" : "true", + "y" : 10, + "align" : "right", + "color" : "#FFFFFF" }, "name" : "Contributions" } ], - "xAxis" : { - "type" : "category", - "labels" : { - "style" : { - "fontFamily" : "Verdana, sans-serif", - "fontSize" : "13px" - } - } - }, - "yAxis" : { - "min" : 0, - "title" : { - "text" : null - } - }, - "subtitle" : { - "text" : "Last updated at 2023-05-29 03:18:17 GMT" - }, - "tooltip" : { - "pointFormat" : "<b>{point.y:.0f}</b>" - }, - "title" : { - "text" : "The Weekly Challenge Contributions [2019 - 2023]" - }, "legend" : { "enabled" : "false" - }, - "chart" : { - "type" : "column" } } diff --git a/stats/pwc-language-breakdown.json b/stats/pwc-language-breakdown.json index c1fab39ac2..83cc5d06dc 100644 --- a/stats/pwc-language-breakdown.json +++ b/stats/pwc-language-breakdown.json @@ -1,30 +1,42 @@ { - "chart" : { - "type" : "column" + "legend" : { + "enabled" : "false" }, "plotOptions" : { "series" : { - "borderWidth" : 0, "dataLabels" : { "enabled" : 1, "format" : "{point.y}" - } + }, + "borderWidth" : 0 } }, - "legend" : { - "enabled" : "false" + "chart" : { + "type" : "column" + }, + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } + }, + "tooltip" : { + "pointFormat" : "<span style=\"color:{point.color}\">Challenge {point.name}</span>: <b>{point.y:f}</b><br/>", + "followPointer" : "true", + "headerFormat" : "<span style=\"font-size:11px\"></span>" + }, + "xAxis" : { + "type" : "category" }, "title" : { "text" : "The Weekly Challenge Language" }, "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2023-05-29 03:18:17 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2023-05-30 08:44:43 GMT" }, "drilldown" : { "series" : [ { "name" : "001", - "id" : "001", "data" : [ [ "Perl", @@ -38,9 +50,11 @@ "Blog", 11 ] - ] + ], + "id" : "001" }, { + "name" : "002", "data" : [ [ "Perl", @@ -55,8 +69,7 @@ 10 ] ], - "id" : "002", - "name" : "002" + "id" : "002" }, { "data" : [ @@ -73,10 +86,11 @@ 9 ] ], - "name" : "003", - "id" : "003" + "id" : "003", + "name" : "003" }, { + "id" : "004", "data" : [ [ "Perl", @@ -91,12 +105,10 @@ 10 ] ], - "name" : "004", - "id" : "004" + "name" : "004" }, { "id" : "005", - "name" : "005", "data" : [ [ "Perl", @@ -110,7 +122,8 @@ "Blog", 12 ] - ] + ], + "name" : "005" }, { "name" : "006", @@ -131,8 +144,6 @@ ] }, { - "id" : "007", - "name" : "007", "data" : [ [ "Perl", @@ -146,10 +157,11 @@ "Blog", 10 ] - ] + ], + "id" : "007", + "name" : "007" }, { - "id" : "008", "name" : "008", "data" : [ [ @@ -164,7 +176,8 @@ "Blog", 12 ] - ] + ], + "id" : "008" }, { "data" : [ @@ -181,8 +194,8 @@ 13 ] ], - "name" : "009", - "id" : "009" + "id" : "009", + "name" : "009" }, { "data" : [ @@ -203,7 +216,6 @@ "name" : "010" }, { - "name" : "011", "id" : "011", "data" : [ [ @@ -218,10 +230,10 @@ "Blog", 10 ] - ] + ], + "name" : "011" }, { - "name" : "012", "id" : "012", "data" : [ [ @@ -236,11 +248,11 @@ "Blog", 11 ] - ] + ], + "name" : "012" }, { "id" : "013", - "name" : "013", "data" : [ [ "Perl", @@ -254,9 +266,12 @@ "Blog", 13 ] - ] + ], + "name" : "013" }, { + "name" : "014", + "id" : "014", "data" : [ [ "Perl", @@ -270,11 +285,10 @@ "Blog", 15 ] - ], - "name" : "014", - "id" : "014" + ] }, { + "id" : "015", "data" : [ [ "Perl", @@ -289,12 +303,9 @@ 15 ] ], - "name" : "015", - "id" : "015" + "name" : "015" }, { - "id" : "016", - "name" : "016", "data" : [ [ "Perl", |
