diff options
| author | Dave Jacoby <jacoby.david@gmail.com> | 2024-01-22 18:10:35 -0500 |
|---|---|---|
| committer | Dave Jacoby <jacoby.david@gmail.com> | 2024-01-22 18:10:35 -0500 |
| commit | a0e4bc1a0527c3055df7a3124993ecb85118e166 (patch) | |
| tree | f75b6a369f51d5931f41b3fe7cee63a7ebec1bde | |
| parent | c24409b0609daed2918cf56465ce398ffbfae68e (diff) | |
| parent | 29b1af3483563eac26835c6c5a6c98c343b1c8a5 (diff) | |
| download | perlweeklychallenge-club-a0e4bc1a0527c3055df7a3124993ecb85118e166.tar.gz perlweeklychallenge-club-a0e4bc1a0527c3055df7a3124993ecb85118e166.tar.bz2 perlweeklychallenge-club-a0e4bc1a0527c3055df7a3124993ecb85118e166.zip | |
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
23 files changed, 3396 insertions, 3060 deletions
diff --git a/challenge-253/jeanluc2020/blog-1.txt b/challenge-253/jeanluc2020/blog-1.txt new file mode 100644 index 0000000000..5614c0a96b --- /dev/null +++ b/challenge-253/jeanluc2020/blog-1.txt @@ -0,0 +1 @@ +http://gott-gehabt.de/800_wer_wir_sind/thomas/Homepage/Computer/perl/theweeklychallenge-253-1.html diff --git a/challenge-253/jeanluc2020/blog-2.txt b/challenge-253/jeanluc2020/blog-2.txt new file mode 100644 index 0000000000..24e85d0fe8 --- /dev/null +++ b/challenge-253/jeanluc2020/blog-2.txt @@ -0,0 +1 @@ +http://gott-gehabt.de/800_wer_wir_sind/thomas/Homepage/Computer/perl/theweeklychallenge-253-2.html diff --git a/challenge-253/jeanluc2020/perl/ch-1.pl b/challenge-253/jeanluc2020/perl/ch-1.pl new file mode 100755 index 0000000000..47f874497c --- /dev/null +++ b/challenge-253/jeanluc2020/perl/ch-1.pl @@ -0,0 +1,48 @@ +#!/usr/bin/env perl +# https://theweeklychallenge.org/blog/perl-weekly-challenge-253/#TASK1 +# +# Task 1: Split Strings +# ===================== +# +# You are given an array of strings and a character separator. +# +# Write a script to return all words separated by the given character excluding +# empty string. +# +# Example 1 +# +# Input: @words = ("one.two.three","four.five","six") +# $separator = "." +# Output: "one","two","three","four","five","six" +# +# Example 2 +# +# Input: @words = ("$perl$$", "$$raku$") +# $separator = "$" +# Output: "perl","raku" +# +############################################################ +## +## discussion +## +############################################################ +# +# This is a classic one-liner problem: join the words into a single string, +# then split this string into an array of strings at the separator, then +# only keep the non-empty strings by grepping for strings that contain one +# character. +# + +use strict; +use warnings; + +split_strings(".", "one.two.three","four.five","six"); +split_strings('$', '$perl$$', '$$raku$'); + +sub split_strings { + my ($separator, @words) = @_; + print "Input: (\"" . join("\", \"", @words) . "\"), '$separator'\n"; + my @output = grep /./, split /\Q$separator\E/, join($separator, @words); + print "Output: (\"" . join("\", \"", @output) . "\")\n"; +} + diff --git a/challenge-253/jeanluc2020/perl/ch-2.pl b/challenge-253/jeanluc2020/perl/ch-2.pl new file mode 100755 index 0000000000..c54a457e4e --- /dev/null +++ b/challenge-253/jeanluc2020/perl/ch-2.pl @@ -0,0 +1,93 @@ +#!/usr/bin/env perl +# https://theweeklychallenge.org/blog/perl-weekly-challenge-253/#TASK2 +# +# Task 2: Weakest Row +# =================== +# +# You are given an m x n binary matrix i.e. only 0 and 1 where 1 always appear before 0. +# +# A row i is weaker than a row j if one of the following is true: +# +## a) The number of 1s in row i is less than the number of 1s in row j. +## b) Both rows have the same number of 1 and i < j. +# +# Write a script to return the order of rows from weakest to strongest. +# +## Example 1 +## +## Input: $matrix = [ +## [1, 1, 0, 0, 0], +## [1, 1, 1, 1, 0], +## [1, 0, 0, 0, 0], +## [1, 1, 0, 0, 0], +## [1, 1, 1, 1, 1] +## ] +## Output: (2, 0, 3, 1, 4) +## +## The number of 1s in each row is: +## - Row 0: 2 +## - Row 1: 4 +## - Row 2: 1 +## - Row 3: 2 +## - Row 4: 5 +# +## Example 2 +## +## Input: $matrix = [ +## [1, 0, 0, 0], +## [1, 1, 1, 1], +## [1, 0, 0, 0], +## [1, 0, 0, 0] +## ] +## Output: (0, 2, 3, 1) +## +## The number of 1s in each row is: +## - Row 0: 1 +## - Row 1: 4 +## - Row 2: 1 +## - Row 3: 1 +# +############################################################ +## +## discussion +## +############################################################ +# +# First, we create a second array which contains the number of 1's +# in each row and the row's index, then we sort that array by the +# number of ones and the index +# + +use strict; +use warnings; + +weakest_row([ [1, 1, 0, 0, 0], [1, 1, 1, 1, 0], [1, 0, 0, 0, 0], [1, 1, 0, 0, 0], [1, 1, 1, 1, 1] ]); +weakest_row([ [1, 0, 0, 0], [1, 1, 1, 1], [1, 0, 0, 0], [1, 0, 0, 0] ]); + +sub weakest_row { + my $matrix = shift; + print "Input: [\n"; + foreach my $array (@$matrix) { + print " [" . join(", ", @$array) . "\,\n"; + } + print " ]\n"; + my @sort_by_me = (); + my $i = 0; + foreach my $array (@$matrix) { + my $num = number_of_ones(@$array); + my $pos = $i; + $i++; + push @sort_by_me, [$num, $pos]; + } + my @sorted = sort { $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1] } @sort_by_me; + print "Output: (" . join(", ", map { $_->[1] } @sorted) . ")\n"; +} + +sub number_of_ones { + my @array = @_; + my $output = 0; + foreach my $value (@array) { + $output++ if $value; + } + return $output; +} diff --git a/challenge-253/jeanluc2020/python/ch-1.py b/challenge-253/jeanluc2020/python/ch-1.py new file mode 100755 index 0000000000..466d4712c2 --- /dev/null +++ b/challenge-253/jeanluc2020/python/ch-1.py @@ -0,0 +1,49 @@ +#!/usr/bin/python3 +# https://theweeklychallenge.org/blog/perl-weekly-challenge-253/#TASK1 +# +# Task 1: Split Strings +# ===================== +# +# You are given an array of strings and a character separator. +# +# Write a script to return all words separated by the given character excluding +# empty string. +# +# Example 1 +# +# Input: @words = ("one.two.three","four.five","six") +# $separator = "." +# Output: "one","two","three","four","five","six" +# +# Example 2 +# +# Input: @words = ("$perl$$", "$$raku$") +# $separator = "$" +# Output: "perl","raku" +# +############################################################ +## +## discussion +## +############################################################ +# +# This is a classic one-liner problem: join the words into a single string, +# then split this string into an array of strings at the separator, then +# only keep the non-empty strings by grepping for strings that contain one +# character. +# + +import re + +def split_strings(separator: str, words: list) -> None: + print("Input: (\"", "\", \"".join(words), "\"), '", separator, "'", sep="") + output = [] + for value in separator.join(words).split(separator): + if len(value) > 0: + output.append(value) + print("Output: (\"", "\", \"".join(output), "\")", sep="") + + +split_strings(".", ["one.two.three","four.five","six"]) +split_strings('$', ['$perl$$', '$$raku$']) + diff --git a/challenge-253/jeanluc2020/python/ch-2.py b/challenge-253/jeanluc2020/python/ch-2.py new file mode 100755 index 0000000000..895f12e674 --- /dev/null +++ b/challenge-253/jeanluc2020/python/ch-2.py @@ -0,0 +1,91 @@ +#!/usr/bin/python3 +# https://theweeklychallenge.org/blog/perl-weekly-challenge-253/#TASK2 +# +# Task 2: Weakest Row +# =================== +# +# You are given an m x n binary matrix i.e. only 0 and 1 where 1 always appear before 0. +# +# A row i is weaker than a row j if one of the following is true: +# +## a) The number of 1s in row i is less than the number of 1s in row j. +## b) Both rows have the same number of 1 and i < j. +# +# Write a script to return the order of rows from weakest to strongest. +# +## Example 1 +## +## Input: $matrix = [ +## [1, 1, 0, 0, 0], +## [1, 1, 1, 1, 0], +## [1, 0, 0, 0, 0], +## [1, 1, 0, 0, 0], +## [1, 1, 1, 1, 1] +## ] +## Output: (2, 0, 3, 1, 4) +## +## The number of 1s in each row is: +## - Row 0: 2 +## - Row 1: 4 +## - Row 2: 1 +## - Row 3: 2 +## - Row 4: 5 +# +## Example 2 +## +## Input: $matrix = [ +## [1, 0, 0, 0], +## [1, 1, 1, 1], +## [1, 0, 0, 0], +## [1, 0, 0, 0] +## ] +## Output: (0, 2, 3, 1) +## +## The number of 1s in each row is: +## - Row 0: 1 +## - Row 1: 4 +## - Row 2: 1 +## - Row 3: 1 +# +############################################################ +## +## discussion +## +############################################################ +# +# First, we create a second array which contains the number of 1's +# in each row and the row's index, then we sort that array by the +# number of ones and the index - which means we only sort by the +# number of ones since python's sort is stable, keeping the order +# of elements intact if the values are the same, and the index is +# therefore already sorted after sorting by number of ones. +# + +from operator import itemgetter + +def number_of_ones( array: list) -> int: + output = 0 + for value in array: + if value > 0: + output += 1 + return output + +def weakest_row(matrix: list) -> None: + print("Input: [") + for array in matrix: + print(" [", ", ".join([str(x) for x in array]), "],") + print(" ]") + sort_by_me = [] + i = 0 + for array in matrix: + num = number_of_ones(array) + pos = i + i += 1 + sort_by_me.append([num, pos]) + sorted_array = sorted(sort_by_me, key=itemgetter(0)) + print("Output: (", ", ".join([str(x[1]) for x in sorted_array]), ")", sep=None) + + +weakest_row([ [1, 1, 0, 0, 0], [1, 1, 1, 1, 0], [1, 0, 0, 0, 0], [1, 1, 0, 0, 0], [1, 1, 1, 1, 1] ]) +weakest_row([ [1, 0, 0, 0], [1, 1, 1, 1], [1, 0, 0, 0], [1, 0, 0, 0] ]) + diff --git a/stats/pwc-challenge-252.json b/stats/pwc-challenge-252.json index 06efe7708a..cf7f3e984c 100644 --- a/stats/pwc-challenge-252.json +++ b/stats/pwc-challenge-252.json @@ -1,11 +1,9 @@ { - "subtitle" : { - "text" : "[Champions: 35] Last updated at 2024-01-22 18:31:03 GMT" + "chart" : { + "type" : "column" }, - "yAxis" : { - "title" : { - "text" : "Total Solutions" - } + "xAxis" : { + "type" : "category" }, "series" : [ { @@ -13,8 +11,8 @@ "colorByPoint" : 1, "data" : [ { - "drilldown" : "Adam Russell", "name" : "Adam Russell", + "drilldown" : "Adam Russell", "y" : 2 }, { @@ -23,59 +21,64 @@ "drilldown" : "Ali Moradi" }, { + "name" : "Arne Sommer", "drilldown" : "Arne Sommer", - "y" : 3, - "name" : "Arne Sommer" + "y" : 3 }, { - "y" : 4, "name" : "Athanasius", - "drilldown" : "Athanasius" + "drilldown" : "Athanasius", + "y" : 4 }, { + "name" : "BarrOff", "drilldown" : "BarrOff", - "y" : 4, - "name" : "BarrOff" + "y" : 4 }, { - "drilldown" : "Bob Lied", "name" : "Bob Lied", + "drilldown" : "Bob Lied", "y" : 2 }, { - "y" : 2, "name" : "Bruce Gray", - "drilldown" : "Bruce Gray" + "drilldown" : "Bruce Gray", + "y" : 2 }, { - "y" : 2, "name" : "Cheok-Yin Fung", - "drilldown" : "Cheok-Yin Fung" + "drilldown" : "Cheok-Yin Fung", + "y" : 2 + }, + { + "name" : "Dave Jacoby", + "y" : 3, + "drilldown" : "Dave Jacoby" }, { "drilldown" : "David Ferrone", - "name" : "David Ferrone", - "y" : 2 + "y" : 2, + "name" : "David Ferrone" }, { "y" : 2, - "name" : "E. Choroba", - "drilldown" : "E. Choroba" + "drilldown" : "E. Choroba", + "name" : "E. Choroba" }, { "drilldown" : "Jaldhar H. Vyas", - "name" : "Jaldhar H. Vyas", - "y" : 5 + "y" : 5, + "name" : "Jaldhar H. Vyas" }, { - "drilldown" : "Jan Krnavek", + "name" : "Jan Krnavek", "y" : 1, - "name" : "Jan Krnavek" + "drilldown" : "Jan Krnavek" }, { - "name" : "Jorg Sommrey", "y" : 3, - "drilldown" : "Jorg Sommrey" + "drilldown" : "Jorg Sommrey", + "name" : "Jorg Sommrey" }, { "drilldown" : "Laurent Rosenfeld", @@ -88,24 +91,24 @@ "drilldown" : "Lubos Kolouch" }, { + "y" : 10, "drilldown" : "Luca Ferrari", - "name" : "Luca Ferrari", - "y" : 10 + "name" : "Luca Ferrari" }, { - "name" : "Mark Anderson", "y" : 2, - "drilldown" : "Mark Anderson" + "drilldown" : "Mark Anderson", + "name" : "Mark Anderson" }, { - "name" : "Matthew Neleigh", "y" : 2, - "drilldown" : "Matthew Neleigh" + "drilldown" : "Matthew Neleigh", + "name" : "Matthew Neleigh" }, { - "drilldown" : "Mustafa Aydin", + "name" : "Mustafa Aydin", "y" : 2, - "name" : "Mustafa Aydin" + "drilldown" : "Mustafa Aydin" }, { "drilldown" : "Nelo Tovar", @@ -113,9 +116,9 @@ "name" : "Nelo Tovar" }, { - "drilldown" : "Niels van Dijke", "name" : "Niels van Dijke", - "y" : 2 + "y" : 2, + "drilldown" : "Niels van Dijke" }, { "drilldown" : "Packy Anderson", @@ -124,13 +127,13 @@ }, { "drilldown" : "Paulo Custodio", - "name" : "Paulo Custodio", - "y" : 2 + "y" : 2, + "name" : "Paulo Custodio" }, { "drilldown" : "Peter Campbell Smith", - "name" : "Peter Campbell Smith", - "y" : 3 + "y" : 3, + "name" : "Peter Campbell Smith" }, { "drilldown" : "Peter Meszaros", @@ -139,8 +142,8 @@ }, { "name" : "Robbie Hatley", - "y" : 3, - "drilldown" : "Robbie Hatley" + "drilldown" : "Robbie Hatley", + "y" : 3 }, { "name" : "Robert Ransbottom", @@ -148,39 +151,39 @@ "drilldown" : "Robert Ransbottom" }, { + "y" : 5, "drilldown" : "Roger Bell_West", - "name" : "Roger Bell_West", - "y" : 5 + "name" : "Roger Bell_West" }, { "y" : 2, - "name" : "Scott Sotka", - "drilldown" : "Scott Sotka" + "drilldown" : "Scott Sotka", + "name" : "Scott Sotka" }, { - "y" : 3, "name" : "Simon Green", + "y" : 3, "drilldown" : "Simon Green" }, { "drilldown" : "Simon Proctor", - "name" : "Simon Proctor", - "y" : 2 + "y" : 2, + "name" : "Simon Proctor" }, { + "name" : "Stephen G. Lynn", "drilldown" : "Stephen G. Lynn", - "y" : 3, - "name" : "Stephen G. Lynn" + "y" : 3 }, { - "drilldown" : "Thomas Kohler", + "name" : "Thomas Kohler", "y" : 4, - "name" : "Thomas Kohler" + "drilldown" : "Thomas Kohler" }, { - "name" : "Ulrich Rieke", "y" : 4, - "drilldown" : "Ulrich Rieke" + "drilldown" : "Ulrich Rieke", + "name" : "Ulrich Rieke" }, { "name" : "W. Luis Mochan", @@ -190,21 +193,47 @@ ] } ], + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } + }, + "plotOptions" : { + "series" : { + "dataLabels" : { + "enabled" : 1, + "format" : "{point.y}" + }, + "borderWidth" : 0 + } + }, + "legend" : { + "enabled" : 0 + }, + "title" : { + "text" : "The Weekly Challenge - 252" + }, + "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/>" + }, + "subtitle" : { + "text" : "[Champions: 36] Last updated at 2024-01-22 21:02:05 GMT" + }, "drilldown" : { "series" : [ { - "name" : "Adam Russell", "data" : [ [ "Perl", 2 ] ], - "id" : "Adam Russell" + "id" : "Adam Russell", + "name" : "Adam Russell" }, { - "name" : "Ali Moradi", - "id" : "Ali Moradi", "data" : [ [ "Perl", @@ -218,9 +247,12 @@ "Blog", 1 ] - ] + ], + "id" : "Ali Moradi", + "name" : "Ali Moradi" }, { + "id" : "Arne Sommer", "data" : [ [ "Raku", @@ -231,7 +263,6 @@ 1 ] ], - "id" : "Arne Sommer", "name" : "Arne Sommer" }, { @@ -249,7 +280,6 @@ ] }, { - "id" : "BarrOff", "data" : [ [ "Perl", @@ -260,17 +290,18 @@ 2 ] ], + "id" : "BarrOff", "name" : "BarrOff" }, { - "id" : "Bob Lied", + "name" : "Bob Lied", "data" : [ [ "Perl", 2 ] ], - "name" : "Bob Lied" + "id" : "Bob Lied" }, { "id" : "Bruce Gray", @@ -283,33 +314,47 @@ "name" : "Bruce Gray" }, { - "id" : "Cheok-Yin Fung", "data" : [ [ "Perl", 2 ] ], + "id" : "Cheok-Yin Fung", "name" : "Cheok-Yin Fung" }, { - "name" : "David Ferrone", + "name" : "Dave Jacoby", "data" : [ [ "Perl", 2 + ], + [ + "Blog", + 1 ] ], - "id" : "David Ferrone" + "id" : "Dave Jacoby" }, { - "id" : "E. Choroba", + "id" : "David Ferrone", "data" : [ [ "Perl", 2 ] ], + "name" : "David Ferrone" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "E. Choroba", "name" : "E. Choroba" }, { @@ -331,17 +376,17 @@ ] }, { - "name" : "Jan Krnavek", "data" : [ [ "Raku", 1 ] ], - "id" : "Jan Krnavek" + "id" : "Jan Krnavek", + "name" : "Jan Krnavek" }, { - "name" : "Jorg Sommrey", + "id" : "Jorg Sommrey", "data" : [ [ "Perl", @@ -352,11 +397,9 @@ 1 ] ], - "id" : "Jorg Sommrey" + "name" : "Jorg Sommrey" }, { - "name" : "Laurent Rosenfeld", - "id" : "Laurent Rosenfeld", "data" : [ [ "Perl", @@ -370,9 +413,12 @@ "Blog", 2 ] - ] + ], + "id" : "Laurent Rosenfeld", + "name" : "Laurent Rosenfeld" }, { + "name" : "Lubos Kolouch", "data" : [ [ "Perl", @@ -383,12 +429,10 @@ 2 ] ], - "id" : "Lubos Kolouch", - "name" : "Lubos Kolouch" + "id" : "Lubos Kolouch" }, { "name" : "Luca Ferrari", - "id" : "Luca Ferrari", "data" : [ [ "Raku", @@ -398,57 +442,58 @@ "Blog", 8 ] - ] + ], + "id" : "Luca Ferrari" }, { - "name" : "Mark Anderson", - "id" : "Mark Anderson", "data" : [ [ "Raku", 2 ] - ] + ], + "id" : "Mark Anderson", + "name" : "Mark Anderson" }, { "name" : "Matthew Neleigh", - "id" : "Matthew Neleigh", "data" : [ [ "Perl", 2 ] - ] + ], + "id" : "Matthew Neleigh" }, { - "name" : "Mustafa Aydin", + "id" : "Mustafa Aydin", "data" : [ [ "Raku", 2 ] ], - "id" : "Mustafa Aydin" + "name" : "Mustafa Aydin" }, { - "id" : "Nelo Tovar", "data" : [ [ "Perl", 2 ] ], + "id" : "Nelo Tovar", "name" : "Nelo Tovar" }, { - "name" : "Niels van Dijke", + "id" : "Niels van Dijke", "data" : [ [ "Perl", 2 ] ], - "id" : "Niels van Dijke" + "name" : "Niels van Dijke" }, { "data" : [ @@ -469,14 +514,14 @@ "name" : "Packy Anderson" }, { - "name" : "Paulo Custodio", + "id" : "Paulo Custodio", "data" : [ [ "Perl", 2 ] ], - "id" : "Paulo Custodio" + "name" : "Paulo Custodio" }, { "data" : [ @@ -493,13 +538,13 @@ "name" : "Peter Campbell Smith" }, { - "id" : "Peter Meszaros", "data" : [ [ "Perl", 2 ] ], + "id" : "Peter Meszaros", "name" : "Peter Meszaros" }, { @@ -527,7 +572,7 @@ "name" : "Robert Ransbottom" }, { - "id" : "Roger Bell_West", + "name" : "Roger Bell_West", "data" : [ [ "Perl", @@ -542,20 +587,20 @@ 1 ] ], - "name" : "Roger Bell_West" + "id" : "Roger Bell_West" }, { "name" : "Scott Sotka", - "id" : "Scott Sotka", "data" : [ [ "Raku", 2 ] - ] + ], + "id" : "Scott Sotka" }, { - "name" : "Simon Green", + "id" : "Simon Green", "data" : [ [ "Perl", @@ -566,7 +611,7 @@ 1 ] ], - "id" : "Simon Green" + "name" : "Simon Green" }, { "name" : "Simon Proctor", @@ -579,7 +624,7 @@ ] }, { - "id" : "Stephen G. Lynn", + "name" : "Stephen G. Lynn", "data" : [ [ "Perl", @@ -590,10 +635,10 @@ 1 ] ], - "name" : "Stephen G. Lynn" + "id" : "Stephen G. Lynn" }, { - "id" : "Thomas Kohler", + "name" : "Thomas Kohler", "data" : [ [ "Perl", @@ -604,10 +649,9 @@ 2 ] ], - "name" : "Thomas Kohler" + "id" : "Thomas Kohler" }, { - "name" : "Ulrich Rieke", "id" : "Ulrich Rieke", "data" : [ [ @@ -618,7 +662,8 @@ "Raku", 2 ] - ] + ], + "name" : "Ulrich Rieke" }, { "data" : [ @@ -635,31 +680,5 @@ |
