diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-02-17 21:02:01 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-02-17 21:02:01 +0000 |
| commit | 1806a0df9eb09b480bb4a31fcd048550f209bdf8 (patch) | |
| tree | a6b8d9b935fedfd58355ad646384959aa7c0d736 | |
| parent | effbc07c282da40daae5c20172e06bbf309ef88c (diff) | |
| download | perlweeklychallenge-club-1806a0df9eb09b480bb4a31fcd048550f209bdf8.tar.gz perlweeklychallenge-club-1806a0df9eb09b480bb4a31fcd048550f209bdf8.tar.bz2 perlweeklychallenge-club-1806a0df9eb09b480bb4a31fcd048550f209bdf8.zip | |
- Added solutions by Lubos Kolouch.
- Added solutions by Mariano Spadaccini.
- Added solutions by Robbie Hatley.
- Added solutions by David Ferrone.
- Added solutions by Arne Sommer.
- Added solutions by Neils van Dijke.
- Added solutions by Roger Bell_West.
- Added solutions by Dave Jacoby.
- Added solutions by Peter Campbell Smith.
- Added solutions by Bob Lied.
- Added solutions by Jorg Sommrey.
- Added solutions by Robert Ransbottom.
- Added solutions by Robert DiCicco.
- Added solutions by Laurent Rosenfeld.
- Added solutions by Matthias Muth.
27 files changed, 2655 insertions, 2127 deletions
diff --git a/challenge-204/laurent-rosenfeld/blog.txt b/challenge-204/laurent-rosenfeld/blog.txt new file mode 100644 index 0000000000..d6ba63a2db --- /dev/null +++ b/challenge-204/laurent-rosenfeld/blog.txt @@ -0,0 +1 @@ +https://blogs.perl.org/users/laurent_r/2023/02/perl-weekly-challenge-204-monotonic-arrays-and-reshape-matrix.html diff --git a/challenge-204/laurent-rosenfeld/perl/ch-1.pl b/challenge-204/laurent-rosenfeld/perl/ch-1.pl new file mode 100644 index 0000000000..e3ac8bac73 --- /dev/null +++ b/challenge-204/laurent-rosenfeld/perl/ch-1.pl @@ -0,0 +1,16 @@ +use strict; +use warnings; +use feature "say"; + +sub is_monotonic { + my @in = @_; + my ($ascending, $descending) = (1, 1); + for my $i (1..$#in) { + $ascending = 0 if $in[$i] < $in[$i-1]; + $descending = 0 if $in[$i] > $in[$i-1] + } + return $ascending || $descending; +} +for my $test ([<1 2 2 3>], [<1 3 2>], [<6 5 5 4>]) { + printf "%-10s => %d\n", "@$test", is_monotonic @$test; +} diff --git a/challenge-204/laurent-rosenfeld/perl/ch-2.pl b/challenge-204/laurent-rosenfeld/perl/ch-2.pl new file mode 100644 index 0000000000..444d0a4899 --- /dev/null +++ b/challenge-204/laurent-rosenfeld/perl/ch-2.pl @@ -0,0 +1,32 @@ +use strict; +use warnings; +use feature "say"; + +sub reshape { + my @matrix = @{$_[0]}; + my ($r, $c) = @{$_[1]}; + my @result; + my $rows = scalar @matrix; + my $cols = scalar @{$matrix[0]}; + return [0] if $r * $c != $rows * $cols; + my @flat = map { @$_ } @matrix; + for my $i (0..$r - 1) { + push @result, [ @flat[$i*$c .. $i*$c + $c -1 ] ]; + } + return @result; +} +sub display_result { + my ($mat, $rc) = @_; + printf "%-15s - %-3s => ", join ("", + map ("[@$_]", @$mat)), "@$rc"; + say map "[@$_]", reshape($mat, $rc);; +} + +my @test = ([1, 2], [3, 4]); +for my $rc ([<1 4>], [<4 1>], [<2 2>], [<3 4>]) { + display_result \@test, $rc; +} +@test = ([1, 2, 3], [4, 5, 6]); +for my $rc ([<3 2>], [<2 3>], [<1 6>], [<6 1>], [<6 3>]) { + display_result \@test, $rc; +} diff --git a/challenge-204/laurent-rosenfeld/raku/ch-1.raku b/challenge-204/laurent-rosenfeld/raku/ch-1.raku new file mode 100644 index 0000000000..bc02ec5c55 --- /dev/null +++ b/challenge-204/laurent-rosenfeld/raku/ch-1.raku @@ -0,0 +1,7 @@ +sub is-monotonic (@in) { + [>=] @in or [<=] @in; +} + +for <1 2 2 3>, <1 3 2>, <6 5 5 4> -> @test { + say (~@test).fmt("%-10s => "), + is-monotonic @test; +} diff --git a/challenge-204/laurent-rosenfeld/raku/ch-2.raku b/challenge-204/laurent-rosenfeld/raku/ch-2.raku new file mode 100644 index 0000000000..aeabc9b43f --- /dev/null +++ b/challenge-204/laurent-rosenfeld/raku/ch-2.raku @@ -0,0 +1,24 @@ +sub reshape (@matrix, $r, $c) { + my @result; + my $rows = @matrix.elems; + my $cols = @matrix[0].elems; + return 0 if $r * $c != $rows * $cols; + my @flattened = | @matrix.map({| $_ }); + for 0..^$r -> $i { + push @result, @flattened[$i*$c .. $i*$c + $c -1 ] + } + return @result; +} +sub display-result (@mat, $rc) { + say @mat.gist.fmt("%-18s - "), "$rc => ", + reshape(@mat, | $rc); +} + +my @test = ((1, 2), (3, 4)); +for <1 4>, <4 1>, <2 2>, <3 4> -> $rc { + display-result @test, $rc; +} +@test = ((1, 2, 3), (4, 5, 6)); +for <3 2>, <2 3>, <1 6>, <6 1>, <6 3> -> $rc { + display-result @test, $rc; +} diff --git a/challenge-204/matthias-muth/blog.txt b/challenge-204/matthias-muth/blog.txt new file mode 100644 index 0000000000..99ffab0af0 --- /dev/null +++ b/challenge-204/matthias-muth/blog.txt @@ -0,0 +1 @@ +https://github.com/manwar/perlweeklychallenge-club/tree/master/challenge-204/matthias-muth#readme diff --git a/challenge-204/robert-dicicco/perl/ch-1.pl b/challenge-204/robert-dicicco/perl/ch-1.pl new file mode 100644 index 0000000000..1564cf2329 --- /dev/null +++ b/challenge-204/robert-dicicco/perl/ch-1.pl @@ -0,0 +1,105 @@ +#!/usr/bin/env perl + +=begin pod + +------------------------------------------------- + +AUTHOR: Robert DiCicco + +DATE : 2023-02-14 + +Challenge 204 Monotonic Array ( Perl ) + +------------------------------------------------- + +=cut + + + +use strict; + +use warnings; + +use feature qw/say/; + +use feature qw(signatures); + +no warnings 'experimental::signatures'; + + + +my @nums = ([1, 2, 2, 3],[1, 3, 2],[6, 5, 5, 4]); + + + +sub CheckIncreasing ($a, $len) { + + my @arr = @$a; + + my $cnt = 0; + + while ($cnt < $len - 1) { + + $arr[$cnt + 1] >= $arr[$cnt] ? $cnt++ : return 0; + + } + + return 1; + +} + + + +sub CheckDecreasing ($a, $len) { + + my @arr=@$a; + + my $cnt = 0; + + while ($cnt < $len - 1) { + + $arr[$cnt + 1] <= $arr[$cnt] ? $cnt++ : return 0; + + } + + return 1; + +} + + + +#my $col; + +for (my $col = 0; $col < scalar(@nums); $col++){ + + my $len = scalar(@nums); + + print("Input: \@nums = (",@{$nums[$col]},")\n"); + + say "0" if (CheckIncreasing(\@{$nums[$col]},$len) == 0) and (CheckDecreasing(\@{$nums[$col]},$len) == 0); + + say "1" if (CheckIncreasing(\@{$nums[$col]},$len) == 1) or (CheckDecreasing(\@{$nums[$col]},$len) == 1); + +} + +=begin pod + +------------------------------------------------- + +SAMPLE OUTPUT + +perl .\Monotones.pl + +Input: @nums = (1223) + +1 + +Input: @nums = (132) + +0 + +Input: @nums = (6554) + +1 + +------------------------------------------------- diff --git a/challenge-204/robert-dicicco/python/ch-1.py b/challenge-204/robert-dicicco/python/ch-1.py new file mode 100644 index 0000000000..f4b9629071 --- /dev/null +++ b/challenge-204/robert-dicicco/python/ch-1.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python + +''' + +------------------------------------------------- + +AUTHOR: Robert DiCicco + +DATE : 2023-02-13 + +Challenge 204 Monotonic Array ( Python ) + +------------------------------------------------- + +''' + + + +nums = [[1,2,2,3],[1,3,2],[6,5,5,4]] + + + +def CheckIncreasing(a,ln): + + cnt = 0 + + while(cnt < ln - 1): + + if (a[cnt+1] >= a[cnt]): + + cnt += 1 + + else: + + return 0 + + return 1 + + + +def CheckDecreasing(a,ln): + + cnt = 0 + + while(cnt < ln - 1): + + if (a[cnt+1] <= a[cnt]): + + cnt += 1 + + else: + + return 0 + + return 1 + + + +for n in nums: + + print("Input: @nums = ",n) + + ln = len(n) + + if ((CheckIncreasing(n,ln) == 0) and (CheckDecreasing(n,ln) == 0)) : + + print("0") + + if ((CheckIncreasing(n,ln) == 1) or (CheckDecreasing(n,ln) == 1)) : + + print("1") + + + +''' + +------------------------------------------------- + +SAMPLE OUTPUT + +python .\Monotones.py + +Input: @nums = [1, 2, 2, 3] + +1 + +Input: @nums = [1, 3, 2] + +0 + +Input: @nums = [6, 5, 5, 4] + +1 + +''' diff --git a/members.json b/members.json index 3b6a4f777f..63c51928d7 100644 --- a/members.json +++ b/members.json @@ -162,6 +162,7 @@ "matt-latusek" : "Matt Latusek", "mattneleigh" : "Matthew Neleigh", "matthew-persico" : "Matthew O. Persico", + "matthias-muth" : "Matthias Muth", "max-kossek" : "Max Kossek", "maxim-kolodyazhny" : "Maxim Kolodyazhny", "maxim-nechaev" : "Maxim Nechaev", diff --git a/stats/pwc-challenge-179.json b/stats/pwc-challenge-179.json index 1e9dc4f5a3..e4ca3fb8d8 100644 --- a/stats/pwc-challenge-179.json +++ b/stats/pwc-challenge-179.json @@ -1,18 +1,169 @@ { - "yAxis" : { - "title" : { - "text" : "Total Solutions" + "chart" : { + "type" : "column" + }, + "series" : [ + { + "data" : [ + { + "name" : "Arne Sommer", + "drilldown" : "Arne Sommer", + "y" : 3 + }, + { + "drilldown" : "Athanasius", + "name" : "Athanasius", + "y" : 4 + }, + { + "y" : 1, + "drilldown" : "Aut0exec", + "name" : "Aut0exec" + }, + { + "drilldown" : "Bob Lied", + "name" : "Bob Lied", + "y" : 2 + }, + { + "y" : 1, + "name" : "Cheok-Yin Fung", + "drilldown" : "Cheok-Yin Fung" + }, + { + "y" : 3, + "name" : "Colin Crain", + "drilldown" : "Colin Crain" + }, + { + "drilldown" : "Dario Mazzeo", + "name" : "Dario Mazzeo", + "y" : 1 + }, + { + "drilldown" : "Duncan C. White", + "name" : "Duncan C. White", + "y" : 1 + }, + { + "y" : 2, + "drilldown" : "E. Choroba", + "name" : "E. Choroba" + }, + { + "drilldown" : "Flavio Poletti", + "name" : "Flavio Poletti", + "y" : 6 + }, + { + "drilldown" : "James Smith", + "name" : "James Smith", + "y" : 3 + }, + { + "y" : 1, + "drilldown" : "Jan Krnavek", + "name" : "Jan Krnavek" + }, + { + "name" : "Jorg Sommrey", + "drilldown" : "Jorg Sommrey", + "y" : 2 + }, + { + "drilldown" : "Laurent Rosenfeld", + "name" : "Laurent Rosenfeld", + "y" : 5 + }, + { + "y" : 8, + "drilldown" : "Luca Ferrari", + "name" : "Luca Ferrari" + }, + { + "name" : "Mark Anderson", + "drilldown" : "Mark Anderson", + "y" : 2 + }, + { + "drilldown" : "Robert DiCicco", + "name" : "Robert DiCicco", + "y" : 2 + }, + { + "drilldown" : "Robert Ransbottom", + "name" : "Robert Ransbottom", + "y" : 2 + }, + { + "y" : 5, + "drilldown" : "Roger Bell_West", + "name" : "Roger Bell_West" + }, + { + "name" : "Simon Green", + "drilldown" : "Simon Green", + "y" : 3 + }, + { + "drilldown" : "Simon Proctor", + "name" : "Simon Proctor", + "y" : 1 + }, + { + "y" : 1, + "drilldown" : "Solathian", + "name" : "Solathian" + }, + { + "name" : "Stephen G. Lynn", + "drilldown" : "Stephen G. Lynn", + "y" : 5 + }, + { + "y" : 3, + "drilldown" : "Ulrich Rieke", + "name" : "Ulrich Rieke" + }, + { + "y" : 3, + "drilldown" : "W. Luis Mochan", + "name" : "W. Luis Mochan" + } + ], + "name" : "The Weekly Challenge - 179", + "colorByPoint" : 1 } + ], + "legend" : { + "enabled" : 0 + }, + "title" : { + "text" : "The Weekly Challenge - 179" + }, + "subtitle" : { + "text" : "[Champions: 25] Last updated at 2023-02-17 19:56:15 GMT" }, "tooltip" : { + "followPointer" : 1, "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>", - "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>", - "followPointer" : 1 + "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>" + }, + "xAxis" : { + "type" : "category" + }, + "plotOptions" : { + "series" : { + "borderWidth" : 0, + "dataLabels" : { + "enabled" : 1, + "format" : "{point.y}" + } + } }, "drilldown" : { "series" : [ { - "name" : "Arne Sommer", "data" : [ [ "Raku", @@ -23,9 +174,11 @@ 1 ] ], - "id" : "Arne Sommer" + "id" : "Arne Sommer", + "name" : "Arne Sommer" }, { + "name" : "Athanasius", "data" : [ [ "Perl", @@ -36,18 +189,27 @@ 2 ] ], - "id" : "Athanasius", - "name" : "Athanasius" + "id" : "Athanasius" }, { + "name" : "Aut0exec", + "id" : "Aut0exec", "data" : [ [ "Perl", 1 ] + ] + }, + { + "data" : [ + [ + "Perl", + 2 + ] ], - "id" : "Aut0exec", - "name" : "Aut0exec" + "id" : "Bob Lied", + "name" : "Bob Lied" }, { "data" : [ @@ -60,7 +222,6 @@ "name" : "Cheok-Yin Fung" }, { - "name" : "Colin Crain", "id" : "Colin Crain", "data" : [ [ @@ -71,37 +232,38 @@ "Blog", 1 ] - ] + ], + "name" : "Colin Crain" }, { + "name" : "Dario Mazzeo", "id" : "Dario Mazzeo", "data" : [ [ "Perl", 1 ] - ], - "name" : "Dario Mazzeo" + ] }, { + "name" : "Duncan C. White", + "id" : "Duncan C. White", "data" : [ [ "Perl", 1 ] - ], - "id" : "Duncan C. White", - "name" : "Duncan C. White" + ] }, { - "name" : "E. Choroba", "id" : "E. Choroba", "data" : [ [ "Perl", 2 ] - ] + ], + "name" : "E. Choroba" }, { "id" : "Flavio Poletti", @@ -122,8 +284,6 @@ "name" : "Flavio Poletti" }, { - "name" : "James Smith", - "id" : "James Smith", "data" : [ [ "Perl", @@ -133,30 +293,31 @@ "Blog", 1 ] - ] + ], + "id" : "James Smith", + "name" : "James Smith" }, { - "name" : "Jan Krnavek", + "id" : "Jan Krnavek", "data" : [ [ "Raku", 1 ] ], - "id" : "Jan Krnavek" + "name" : "Jan Krnavek" }, { - "name" : "Jorg Sommrey", + "id" : "Jorg Sommrey", "data" : [ [ "Perl", 2 ] ], - "id" : "Jorg Sommrey" + "name" : "Jorg Sommrey" }, { - "name" : "Laurent Rosenfeld", "id" : "Laurent Rosenfeld", "data" : [ [ @@ -171,7 +332,8 @@ "Blog", 1 ] - ] + ], + "name" : "Laurent Rosenfeld" }, { "data" : [ @@ -189,13 +351,13 @@ }, { "name" : "Mark Anderson", - "id" : "Mark Anderson", "data" : [ [ "Raku", 2 ] - ] + ], + "id" : "Mark Anderson" }, { "data" : [ @@ -213,15 +375,16 @@ }, { "name" : "Robert Ransbottom", - "id" : "Robert Ransbottom", "data" : [ [ "Raku", 2 ] - ] + ], + "id" : "Robert Ransbottom" }, { + "name" : "Roger Bell_West", "id" : "Roger Bell_West", "data" : [ [ @@ -236,8 +399,7 @@ "Blog", 1 ] - ], - "name" : "Roger Bell_West" + ] }, { "name" : "Simon Green", @@ -254,27 +416,27 @@ ] }, { - "name" : "Simon Proctor", + "id" : "Simon Proctor", "data" : [ [ "Raku", 1 ] ], - "id" : "Simon Proctor" + "name" : "Simon Proctor" }, { + "name" : "Solathian", "id" : "Solathian", "data" : [ [ "Perl", 1 ] - ], - "name" : "Solathian" + ] }, { - "id" : "Stephen G Lynn", + "id" : "Stephen G. Lynn", "data" : [ [ "Perl", @@ -289,10 +451,10 @@ 1 ] ], - "name" : "Stephen G Lynn" + "name" : "Stephen G. Lynn" }, { - "name" : "Ulrich Rieke", + "id" : "Ulrich Rieke", "data" : [ [ "Perl", @@ -303,10 +465,10 @@ 2 ] ], - "id" : "Ulrich Rieke" + "name" : "Ulrich Rieke" }, { - "name" : "W. Luis Mochan", + "id" : "W. Luis Mochan", "data" : [ [ "Perl", @@ -317,160 +479,13 @@ 1 ] ], - "id" : "W. Luis Mochan" + "name" : "W. Luis Mochan" } ] }, - "xAxis" : { - "type" : "category" - }, - "title" : { - "text" : "The Weekly Challenge - 179" - }, - "plotOptions" : { - "series" : { - "dataLabels" : { - "format" : "{point.y}", - "enabled" : 1 - }, - "borderWidth" : 0 - } - }, - "chart" : { - "type" : "column" - }, - "legend" : { - "enabled" : 0 - }, - "series" : [ - { - "colorByPoint" : 1, - "name" : "The Weekly Challenge - 179", - "data" : [ - { - "drilldown" : "Arne Sommer", - "name" : "Arne Sommer", - "y" : 3 - }, - { - "drilldown" : "Athanasius", - "name" : "Athanasius", - "y" : 4 - }, - { - "y" : 1, - "name" : "Aut0exec", - "drilldown" : "Aut0exec" - }, - { - "name" : "Cheok-Yin Fung", - "y" : 1, - "drilldown" : "Cheok-Yin Fung" - }, - { - "drilldown" : "Colin Crain", - "name" : "Colin Crain", - "y" : 3 - }, - { - "y" : 1, - "name" : "Dario Mazzeo", - "drilldown" : "Dario Mazzeo" - }, - { - "drilldown" : "Duncan C. White", - "y" : 1, - "name" : "Duncan C. White" - }, - { - "drilldown" : "E. Choroba", - "y" : 2, - "name" : "E. Choroba" - }, - { - "drilldown" : "Flavio Poletti", - "y" : 6, - "name" : "Flavio Poletti" - }, - { - "name" : "James Smith", - "y" : 3, - "drilldown" : "James Smith" - }, - { - "drilldown" : "Jan Krnavek", - "y" : 1, - "name" : "Jan Krnavek" - }, - { - "drilldown" : "Jorg Sommrey", - "name" : "Jorg Sommrey", - "y" : 2 - }, - { - "name" : "Laurent Rosenfeld", - "y" : 5, - "drilldown" : "Laurent Rosenfeld" - }, - { - "drilldown" : "Luca Ferrari", - "name" : "Luca Ferrari", - "y" : 8 - }, - { - "y" : 2, - "name" : "Mark Anderson", - "drilldown" : "Mark Anderson" - }, - { - "name" : "Robert DiCicco", - "y" : 2, - "drilldown" : "Robert DiCicco" - }, - { - "drilldown" : "Robert Ransbottom", - "name" : "Robert Ransbottom", - "y" : 2 - }, - { - "name" : "Roger Bell_West", - "y" : 5, - "drilldown" : "Roger Bell_West" - }, - { - "y" : 3, - "name" : "Simon Green", - "drilldown" : "Simon Green" - }, - { - "y" : 1, - "name" : "Simon Proctor", - "drilldown" : "Simon Proctor" - }, - { - "drilldown" : "Solathian", - "name" : "Solathian", - "y" : 1 - }, - { - "drilldown" : "Stephen G Lynn", - "y" : 5, - "name" : "Stephen G Lynn" - }, - { - "name" : "Ulrich Rieke", - "y" : 3, - "drilldown" : "Ulrich Rieke" - }, - { - "name" : "W. Luis Mochan", - "y" : 3, - "drilldown" : "W. Luis Mochan" - } - ] + "yAxis" : { + "title" : { + "text" : "Total Solutions" } - ], - "subtitle" : { - "text" : "[Champions: 24] Last updated at 2022-08-31 17:37:22 GMT" } } diff --git a/stats/pwc-challenge-202.json b/stats/pwc-challenge-202.json index 417bed8b69..9bbeb3ec35 100644 --- a/stats/pwc-challenge-202.json +++ b/stats/pwc-challenge-202.json @@ -1,200 +1,12 @@ { - "title" : { - "text" : "The Weekly Challenge - 202" - }, - "plotOptions" : { - "series" : { - "borderWidth" : 0, - "dataLabels" : { - "enabled" : 1, - "format" : "{point.y}" - } - } - }, "legend" : { "enabled" : 0 }, - "series" : [ - { - "data" : [ - { - "y" : 3, - "name" : "Adam Russell", - "drilldown" : "Adam Russell" - }, - { - "drilldown" : "Arne Sommer", |
