diff options
23 files changed, 3158 insertions, 2615 deletions
diff --git a/challenge-211/laurent-rosenfeld/blog.txt b/challenge-211/laurent-rosenfeld/blog.txt new file mode 100644 index 0000000000..e6a617dc8e --- /dev/null +++ b/challenge-211/laurent-rosenfeld/blog.txt @@ -0,0 +1 @@ +https://blogs.perl.org/users/laurent_r/2023/04/perl-weekly-challenge-211-toeplitz-matrix-and-split-same-average.html diff --git a/challenge-211/laurent-rosenfeld/perl/ch-1.pl b/challenge-211/laurent-rosenfeld/perl/ch-1.pl new file mode 100644 index 0000000000..95d8293879 --- /dev/null +++ b/challenge-211/laurent-rosenfeld/perl/ch-1.pl @@ -0,0 +1,24 @@ +use strict; +use warnings; +use feature "say"; + +sub is_toeplitz { + my @in = @_; + my $j_max = scalar @{$in[0]} - 1; + for my $i (1..$#in) { + for my $j (1..$j_max) { + # say "$i $j $in[$i][$j] $in[$i-1][$j-1]"; + return "false" if $in[$i][$j] != $in[$i-1][$j-1]; + } + } + return "true"; +} + +for my $test + ( [ [<4 3 2 1>], [<5 4 3 2>], [<6 5 4 3>] ], + [ [<3 2 1 0>], [<4 3 2 1>], [<5 4 3 2>] ], + [ [<3 2 1 0>], [<4 3 2 1>], [<5 5 3 2>] ], + [ [<1 2 3>], [<3 2 1>] ] ) { + say "[ ", (join ", ", map "[@$_]", @$test), " ]"; + say is_toeplitz(@$test), "\n"; +} diff --git a/challenge-211/laurent-rosenfeld/perl/ch-2.pl b/challenge-211/laurent-rosenfeld/perl/ch-2.pl new file mode 100644 index 0000000000..cdba7c0456 --- /dev/null +++ b/challenge-211/laurent-rosenfeld/perl/ch-2.pl @@ -0,0 +1,47 @@ +use strict; +use warnings; +use feature "say"; + +my ($target, @result); + +sub avg { + my $nb_elems = scalar @_; + my $sum = shift; + $sum += $_ for @_; + return $sum / $nb_elems; +} + +sub find_partition { + my @current = @{$_[0]}; + my @left = @{$_[1]}; + return if scalar @left <= 1; + if (scalar @current > 0 and $target == avg(@current)) { + push @result, @current; + return; + } + for my $i (0..$#left) { + find_partition( [@current, $left[$i]], [@left[0..$i-1, $i+1..$#left]]); + return if @result > 0; + } +} + +sub start_partition { + my @in = @_; + $target = avg @in; + @result = (); + my @current; + find_partition [@current], [@in]; + return @result; +} + +for my $test ([<1 2 3 4 5 6 7 8>], [<1 2 3>], [<1 3>]) { + my @output = start_partition @$test; + print "@$test => "; + if (scalar @output == 0) { + say "false"; + } else { + print "true : [@output] "; + my %out = map { $_ => 1 } @output; + say "[", join " ", grep { not exists $out{$_} } @$test, "]"; + } +} diff --git a/challenge-211/laurent-rosenfeld/raku/ch-1.raku b/challenge-211/laurent-rosenfeld/raku/ch-1.raku new file mode 100644 index 0000000000..4ccc4b99c0 --- /dev/null +++ b/challenge-211/laurent-rosenfeld/raku/ch-1.raku @@ -0,0 +1,18 @@ +sub is-toeplitz (@in) { + for 1..@in.end -> $i { + for 1..@in[0].end -> $j { + # say "$i $j @in[$i][$j] @in[$i-1][$j-1]"; + return False if @in[$i][$j] != @in[$i-1][$j-1]; + } + } + return True; +} + + +for ( <4 3 2 1>, <5 4 3 2>, <6 5 4 3> ), + ( <3 2 1 0>, <4 3 2 1>, <5 4 3 2> ), + ( <3 2 1 0>, <4 3 2 1>, <5 5 3 2> ), + ( <1 2 3>, <3 2 1> ) -> @test { + say @test; + say is-toeplitz(@test), "\n"; +} diff --git a/challenge-211/laurent-rosenfeld/raku/ch-2.raku b/challenge-211/laurent-rosenfeld/raku/ch-2.raku new file mode 100644 index 0000000000..4a085341eb --- /dev/null +++ b/challenge-211/laurent-rosenfeld/raku/ch-2.raku @@ -0,0 +1,35 @@ +sub avg (@a) { return ([+] @a) / @a.elems; } + +sub find-partition (@current, @left) { + return if @left.elems <= 1; + # say "Current: ", avg @current if @current.elems > 0; + if @current.elems > 0 and $*target == avg @current { + push @*result, @current; + return; + } + for 0..@left.end -> $i { + find-partition( (@current, @left[$i]).flat, + (@left[0..$i-1, $i+1..@left.end]).flat); + return if @*result.elems > 0; + } +} + +sub start-partition (@in) { + my $*target = avg @in; + my @*result; + my @current; + find-partition @current, @in; + return @*result; +} + +for <1 2 3 4 5 6 7 8>, <1 2 3>, <1 3> -> @test { + my @output = start-partition @test; + print @test, " => "; + if @output.elems == 0 { + say "false"; + } else { + print "true : "; + push @output, (@test (-) @output[0]).keys; + say @output; + } +} diff --git a/challenge-211/robert-dicicco/perl/ch-1.pl b/challenge-211/robert-dicicco/perl/ch-1.pl new file mode 100644 index 0000000000..828a7b2f61 --- /dev/null +++ b/challenge-211/robert-dicicco/perl/ch-1.pl @@ -0,0 +1,87 @@ +#!/usr/bin/env perl +=begin pod +------------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-04-08 +Challenge 211 Toeplitz Matrix ( Perl ) +------------------------------------------- +=cut +use strict; +use warnings; +use feature 'say'; +use List::MoreUtils qw(uniq); + +#my @matrix = ([4, 3, 2, 1],[5, 4, 3, 2],[6, 5, 4, 3]); +my @matrix = ([1,2,3],[3,2,1]); + +my $cols = scalar @{$matrix[0]}; +my $rows = scalar @matrix; + +my $r = 0; +my $c = 0; +my @out = (); +my $flag = 0; + +sub CheckDiag { + my @o = @{$_[0]}; + my @o_u = uniq @o; + if (scalar @o_u != 1) { + $flag = -1 + } +} + +sub Diag { + @out = (); + while ($r < $rows) { + push(@out,$matrix[$r][$c]); + if ($r == $rows - 1) { + CheckDiag(\@out); + return; + } else { + if ($c == $cols - 1) { + CheckDiag(\@out); + last; + }; + $c++; + $r++; + } + } +} + +my $x = 0; +print "Input matrix = [ "; +while ($x < $rows) { + print "[",@{$matrix[$x++]},"] "; +} + +$c = 0; +$r = 0; +while ($c < $cols - 1) { + Diag($c,$r); + $c++; +} + +$r = 1; +$c = 0; +while ($r < $rows - 1) { + Diag($c,$r); + $r++; +} +print "]\n"; + +$flag == -1 ? say "Output: false" : say "Output: true"; + +=begin pod +------------------------------------------- +SAMPLE OUTPUT +perl .\Toeplitz.pl +Input matrix = [ [4321] [5432] [6543] ] +Output: true + +perl .\Toeplitz.pl +Input matrix = [ [123] [321] ] +Output: false +------------------------------------------- +=cut + + diff --git a/challenge-211/robert-dicicco/perl/ch-2.pl b/challenge-211/robert-dicicco/perl/ch-2.pl new file mode 100644 index 0000000000..2a8d63a014 --- /dev/null +++ b/challenge-211/robert-dicicco/perl/ch-2.pl @@ -0,0 +1,70 @@ +#!/usr/bin/env perl +=begin pod +---------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-04-09 +Challenge 211 Split Same Average ( Perl ) +---------------------------------------- +=cut + +use strict; +use warnings; +use feature 'say'; +use Algorithm::Combinatorics qw(combinations); +use List::Util qw/sum/; + +my @nums = (1,2,3,4,5,6,7,8); +#my @nums = (1,3); + +my $flag = 0; +my %seen; # lookup table +my @sec; # answer + +say "Input: \@nums = (@nums)"; + +if (scalar @nums <= 2) { + say "Output: false"; + exit; +} + +my $iter = combinations(\@nums, 4); +while (my $pn = $iter->next) { + @sec = (); + %seen = (); + my $first = sum(@$pn) / scalar(@$pn); + + foreach my $item (@$pn) { $seen{$item} = 1 } + + foreach my $item (@nums) { + push(@sec, $item) unless exists $seen{$item}; + } + + my $second = sum(@sec) / scalar @sec; + if ($first == $second) { $flag = 1}; + say "-----> (@$pn),(@sec), $first : $second" if $first == $second; +} + +$flag == 1 ? (say "Output: true") : (say "Output: false"); + +=begin pod +---------------------------------------- +SAMPLE OUTPUT +perl .\SplitSame.pl|more +Input: @nums = (1 2 3 4 5 6 7 8) +-----> (1 2 7 8),(3 4 5 6), 4.5 : 4.5 +-----> (1 3 6 8),(2 4 5 7), 4.5 : 4.5 +-----> (1 4 5 8),(2 3 6 7), 4.5 : 4.5 +-----> (1 4 6 7),(2 3 5 8), 4.5 : 4.5 +-----> (2 3 5 8),(1 4 6 7), 4.5 : 4.5 +-----> (2 3 6 7),(1 4 5 8), 4.5 : 4.5 +-----> (2 4 5 7),(1 3 6 8), 4.5 : 4.5 +-----> (3 4 5 6),(1 2 7 8), 4.5 : 4.5 +Output: true + perl .\SplitSame.pl +Input: @nums = (1 3) +Output: false +---------------------------------------- +=cut + + + diff --git a/challenge-211/robert-dicicco/python/ch-1.py b/challenge-211/robert-dicicco/python/ch-1.py new file mode 100644 index 0000000000..6c17e9d14d --- /dev/null +++ b/challenge-211/robert-dicicco/python/ch-1.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python +''' +------------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-04-09 +Challenge 211 Toeplitz Matrix ( Python ) +------------------------------------------- +''' + +matrx = [ [4, 3, 2, 1],[5, 4, 3, 2],[6, 5, 4, 3], ] +#matrx = [ [1,2,3],[3,2,1] ] + +rows = len(matrx) +cols = len(matrx[0]) + +r = 0 +c = 0 + +outarr = [] +flag = 0 + +def unique(list1): + unique_list = [] + for x in list1: + if x not in unique_list: + unique_list.append(x) + return unique_list + +def CheckDiag(o): + global flag + arr_u = unique(o) + ln = len(arr_u) + if (ln != 1) : + flag = -1 + +def Diag(c,r): + outarr = [] + while r < rows: + outarr.append(matrx[r][c]) + if r == rows - 1: + CheckDiag(outarr) + return + else: + if c == cols - 1: + CheckDiag(outarr) + break + c += 1 + r += 1 + +print("Input: @matrix = ",matrx) + +c = 0 +r = 0 + +while c < cols - 1: + Diag(c,r) + c += 1 +r = 1 +c = 0 +while r < rows - 1: + Diag(c,r) + r = r + 1 + +print("Output: false") if (flag == -1) else print("Output: true") + +''' +------------------------------------------- +SAMPLE OUTPUT +python .\Toeplitz.py +Input: @matrix = [[4, 3, 2, 1], [5, 4, 3, 2], [6, 5, 4, 3]] +Output: true + +python .\Toeplitz.py +Input: @matrix = [[1, 2, 3], [3, 2, 1]] +Output: false +------------------------------------------- +''' + + diff --git a/stats/pwc-current.json b/stats/pwc-current.json index 2eabbeb57d..c007e2dfc8 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,148 +1,4 @@ { - "subtitle" : { - "text" : "[Champions: 25] Last updated at 2023-04-09 10:48:18 GMT" - }, - "series" : [ - { - "name" : "The Weekly Challenge - 211", - "data" : [ - { - "y" : 3, - "name" : "Arne Sommer", - "drilldown" : "Arne Sommer" - }, - { - "drilldown" : "Carlos Oliveira", - "name" : "Carlos Oliveira", - "y" : 2 - }, - { - "y" : 2, - "drilldown" : "David Ferrone", - "name" : "David Ferrone" - }, - { - "drilldown" : "E. Choroba", - "name" : "E. Choroba", - "y" : 2 - }, - { - "name" : "Flavio Poletti", - "drilldown" : "Flavio Poletti", - "y" : 6 - }, - { - "name" : "James Smith", - "drilldown" : "James Smith", - "y" : 3 - }, - { - "y" : 2, - "drilldown" : "Jorg Sommrey", - "name" : "Jorg Sommrey" - }, - { - "y" : 1, - "drilldown" : "Leo Manfredi", - "name" : "Leo Manfredi" - }, - { - "drilldown" : "Luca Ferrari", - "name" : "Luca Ferrari", - "y" : 8 - }, - { - "drilldown" : "Mariano Spadaccini", - "name" : "Mariano Spadaccini", - "y" : 1 - }, - { - "name" : "Mark Anderson", - "drilldown" : "Mark Anderson", - "y" : 2 - }, - { - "y" : 2, - "name" : "Matthias Muth", - "drilldown" : "Matthias Muth" - }, - { - "y" : 2, - "drilldown" : "Paulo Custodio", - "name" : "Paulo Custodio" - }, - { - "y" : 3, - "name" : "Peter Campbell Smith", - "drilldown" : "Peter Campbell Smith" - }, - { - "drilldown" : "Peter Meszaros", - "name" : "Peter Meszaros", - "y" : 2 - }, - { - "y" : 4, - "drilldown" : "Pip Stuart", - "name" : "Pip Stuart" - }, - { - "y" : 3, - "drilldown" : "Robbie Hatley", - "name" : "Robbie Hatley" - }, - { - "drilldown" : "Robert DiCicco", - "name" : "Robert DiCicco", - "y" : 2 - }, - { - "drilldown" : "Robert Ransbottom", - "name" : "Robert Ransbottom", - "y" : 2 - }, - { - "name" : "Roger Bell_West", - "drilldown" : "Roger Bell_West", - "y" : 4 - }, - { - "drilldown" : "Simon Green", - "name" : "Simon Green", - "y" : 3 - }, - { - "y" : 2, - "name" : "Solathian", - "drilldown" : "Solathian" - }, - { - "y" : 4, - "name" : "Thomas Kohler", - "drilldown" : "Thomas Kohler" - }, - { - "y" : 3, - "drilldown" : "Ulrich Rieke", - "name" : "Ulrich Rieke" - }, - { - "name" : "W. Luis Mochan", - "drilldown" : "W. Luis Mochan", - "y" : 3 - } - ], - "colorByPoint" : 1 - } - ], - "yAxis" : { - "title" : { - "text" : "Total Solutions" - } - }, - "legend" : { - "enabled" : 0 - }, "plotOptions" : { "series" : { "dataLabels" : { @@ -152,6 +8,12 @@ "borderWidth" : 0 } }, + "chart" : { + "type" : "column" + }, + "legend" : { + "enabled" : 0 + }, "drilldown" : { "series" : [ { @@ -169,36 +31,105 @@ "id" : "Arne Sommer" }, { + "id" : "Athanasius", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ] + ], + "name" : "Athanasius" + }, + { + "name" : "Avery Adams", + "id" : "Avery Adams", + "data" : [ + [ + "Perl", + 2 + ] + ] + }, + { + "name" : "BarrOff", + "data" : [ + [ + "Raku", + 2 + ] + ], + "id" : "BarrOff" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Bob Lied", + "name" : "Bob Lied" + }, + { + "name" : "Bruce Gray", + "data" : [ + [ + "Raku", + 2 + ] + ], + "id" : "Bruce Gray" + }, + { "name" : "Carlos Oliveira", + "id" : "Carlos Oliveira", + "data" : [ + [ + "Perl", + 2 + ] + ] + }, + { "data" : [ [ "Perl", 2 ] ], - "id" : "Carlos Oliveira" + "id" : "Cheok-Yin Fung", + "name" : "Cheok-Yin Fung" }, { + "name" : "David Ferrone", "data" : [ [ "Perl", 2 ] ], - "id" : "David Ferrone", - "name" : "David Ferrone" + "id" : "David Ferrone" }, { - "id" : "E. Choroba", + "name" : "E. Choroba", "data" : [ [ "Perl", 2 ] ], - "name" : "E. Choroba" + "id" : "E. Choroba" }, { + "id" : "Flavio Poletti", "data" : [ [ "Perl", @@ -213,45 +144,89 @@ 2 ] ], - "id" : "Flavio Poletti", "name" : "Flavio Poletti" }, { - "name" : "James Smith", "data" : [ [ "Perl", 2 ], [ + "Raku", + 2 + ], + [ "Blog", 1 ] ], - "id" : "James Smith" + "id" : "Jaldhar H. Vyas", + "name" : "Jaldhar H. Vyas" }, { "data" : [ [ "Perl", 2 + ], + [ + "Blog", + 1 ] ], + "id" : "James Smith", + "name" : "James Smith" + }, + { + "data" : [ + [ + "Raku", + 2 + ] + ], + "id" : "Jan Krnavek", + "name" : "Jan Krnavek" + }, + { + "name" : "Jorg Sommrey", "id" : "Jorg Sommrey", - "name" : "Jorg Sommrey" + "data" : [ + [ + "Perl", + 2 + ] + ] + }, + { + "name" : "Laurent Rosenfeld", + "id" : "Laurent Rosenfeld", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ] }, { + "name" : "Leo Manfredi", "id" : "Leo Manfredi", "data" : [ [ "Perl", 1 ] - ], - "name" : "Leo Manfredi" + ] }, { - "name" : "Luca Ferrari", "id" : "Luca Ferrari", "data" : [ [ @@ -262,37 +237,48 @@ "Blog", 6 ] - ] + ], + "name" : "Luca Ferrari" }, { - "name" : "Mariano Spadaccini", + "id" : "Mariano Spadaccini", "data" : [ [ "Perl", 1 ] ], - "id" : "Mariano Spadaccini" + "name" : "Mariano Spadaccini" }, { - "name" : "Mark Anderson", "id" : "Mark Anderson", "data" : [ [ "Raku", 2 ] - ] + ], + "name" : "Mark Anderson" }, { - "id" : "Matthias Muth", + "name" : "Matthew Neleigh", + "data" : [ + [ + "Perl", + 1 + ] + ], + "id" : "Matthew Neleigh" + }, + { + "name" : "Matthias Muth", "data" : [ [ "Perl", 2 ] ], - "name" : "Matthias Muth" + "id" : "Matthias Muth" }, { "name" : "Paulo Custodio", @@ -305,6 +291,8 @@ "id" : "Paulo Custodio" }, { + "name" : "Peter Campbell Smith", + "id" : "Peter Campbell Smith", "data" : [ [ "Perl", @@ -314,18 +302,16 @@ "Blog", 1 ] - ], - "id" : "Peter Campbell Smith", - "name" : "Peter Campbell Smith" + ] }, { + "id" : "Peter Meszaros", "data" : [ [ "Perl", 2 ] ], - "id" : "Peter Meszaros", "name" : "Peter Meszaros" }, { @@ -357,23 +343,27 @@ "id" : "Robbie Hatley" }, { - "id" : "Robert DiCicco", + "name" : "Robert DiCicco", "data" : [ [ + "Perl", + 2 + ], + [ "Raku", 2 ] ], - "name" : "Robert DiCicco" + "id" : "Robert DiCicco" }, { + "id" : "Robert Ransbottom", "data" : [ [ "Raku", 2 ] ], - "id" : "Robert Ransbottom", "name" : "Robert Ransbottom" }, { @@ -386,12 +376,15 @@ [ "Raku", 2 + ], + [ + "Blog", + 1 ] ], "id" : "Roger Bell_West" }, { - "id" : "Simon Green", "data" : [ [ "Perl", @@ -402,6 +395,7 @@ 1 ] ], + "id" : "Simon Green", "name" : "Simon Green" }, { @@ -415,6 +409,7 @@ "name" : "Solathian" }, { + "name" : "Thomas Kohler", "data" : [ [ "Perl", @@ -425,11 +420,9 @@ 2 ] ], - "id" : "Thomas Kohler", - "name" : "Thomas Kohler" + "id" : "Thomas Kohler" }, { - "name" : "Ulrich Rieke", "id" : "Ulrich Rieke", "data" : [ [ @@ -440,7 +433,8 @@ "Raku", 1 ] - ] + ], + "name" : "Ulrich Rieke" }, { "name" : "W. Luis Mochan", @@ -458,18 +452,206 @@ } ] }, - "chart" : { - "type" : "column" + "subtitle" : { + "text" : "[Champions: 35] Last updated at 2023-04-10 00:04:04 GMT" }, "xAxis" : { "type" : "category" }, - "title" : { - "text" : "The Weekly Challenge - 211" - }, "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/>" + "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>", + "followPointer" : 1 + }, + "series" : [ + { + "name" : "The Weekly Challenge - 211", + "colorByPoint" : 1, + "data" : [ + { + "y" : 3, + "drilldown" : "Arne Sommer", + "name" : "Arne Sommer" + }, + { + "name" : "Athanasius", + "drilldown" : "Athanasius", + "y" : 4 + }, + { + "y" : 2, + "drilldown" : "Avery Adams", + "name" : "Avery Adams" + }, + { + "name" : "BarrOff", + "y" : 2, + "drilldown" : "BarrOff" + }, + { + "drilldown" : "Bob Lied", + "y" : 3, + "name" : "Bob Lied" + }, + { + "name" : "Bruce Gray", + "drilldown" : "Bruce Gray", + "y" : 2 + }, + { + "drilldown" : "Carlos Oliveira", + "y" : 2, + "name" : "Carlos Oliveira" + }, + { + "y" : 2, + "drilldown" : "Cheok-Yin Fung", + "name" : "Cheok-Yin Fung" + }, + { + "name" : "David Ferrone", + "y" : 2, + "drilldown" : "David Ferrone" + }, + { + "name" : "E. Choroba", + "drilldown" : "E. Choroba", + "y" : 2 + }, + { + "drilldown" : "Flavio Poletti", + "y" : 6, + "name" : "Flavio Poletti" + }, + { + "name" : "Jaldhar H. Vyas", + "drilldown" : "Jaldhar H. Vyas", + "y" : 5 + }, + { + "name" : "James Smith", + "y" : 3, + "drilldown" : "James Smith" + }, + { + "y" : 2, + "drilldown" : "Jan Krnavek", + "name" : "Jan Krnavek" + }, + { + "y" : 2, + "drilldown" : "Jorg Sommrey", + "name" : "Jorg Sommrey" + }, + { + "y" : 5, + "drilldown" : "Laurent Rosenfeld", + |
