diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2024-04-23 17:07:42 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2024-04-23 17:07:42 +0100 |
| commit | f46d7880f5909abd6b910b372c2b4432ff65b208 (patch) | |
| tree | a386b3ab3434c1e6a33ce62a64b0e1a737e6b15c | |
| parent | 37f7609f7aae7d74954aba280957e140e9fd9bcd (diff) | |
| download | perlweeklychallenge-club-f46d7880f5909abd6b910b372c2b4432ff65b208.tar.gz perlweeklychallenge-club-f46d7880f5909abd6b910b372c2b4432ff65b208.tar.bz2 perlweeklychallenge-club-f46d7880f5909abd6b910b372c2b4432ff65b208.zip | |
- Added solutions by Eric Cheung.
- Added solutions by Reinier Maliepaard.
- Added solutions by Niels van Dijke.
- Added solutions by Feng Chang.
- Added solutions by E. Choroba.
- Added solutions by Mark Anderson.
- Added solutions by Luca Ferrari.
- Added solutions by David Ferrone.
- Added solutions by W. Luis Mochan.
- Added solutions by Peter Meszaros.
- Added solutions by Steven Wilson.
- Added solutions by Roger Bell_West.
- Added solutions by Bob Lied.
- Added solutions by Peter Campbell Smith.
- Added solutions by Lubos Kolouch.
26 files changed, 4269 insertions, 3836 deletions
diff --git a/challenge-266/eric-cheung/python/ch-1.py b/challenge-266/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..160e4be8c9 --- /dev/null +++ b/challenge-266/eric-cheung/python/ch-1.py @@ -0,0 +1,25 @@ +
+## Example 1
+## strLine_01 = "Mango is sweet"
+## strLine_02 = "Mango is sour"
+
+## Example 2
+## strLine_01 = "Mango Mango"
+## strLine_02 = "Orange"
+
+## Example 3
+strLine_01 = "Mango is Mango"
+strLine_02 = "Orange is Orange"
+
+arrLineSplit_01 = strLine_01.split()
+arrUniqLine_01 = [strLoop for strLoop in set(arrLineSplit_01) if arrLineSplit_01.count(strLoop) == 1]
+
+arrLineSplit_02 = strLine_02.split()
+arrUniqLine_02 = [strLoop for strLoop in set(arrLineSplit_02) if arrLineSplit_02.count(strLoop) == 1]
+
+arrUnCommonWord = [strLoop for strLoop in arrUniqLine_01 if not strLoop in arrUniqLine_02]
+arrUnCommonWord = arrUnCommonWord + [strLoop for strLoop in arrUniqLine_02 if not strLoop in arrUniqLine_01]
+
+## print (arrUniqLine_01)
+## print (arrUniqLine_02)
+print (arrUnCommonWord)
diff --git a/challenge-266/eric-cheung/python/ch-2.py b/challenge-266/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..0c74ebfbf3 --- /dev/null +++ b/challenge-266/eric-cheung/python/ch-2.py @@ -0,0 +1,34 @@ +
+def IsXMatrix (arrInputMatrix):
+
+ nLen = len(arrInputMatrix)
+
+ ## Check
+ for nRowIndx in range(nLen):
+
+ nColIndx_01 = nRowIndx
+ nColIndx_02 = nLen - nRowIndx - 1
+
+ ## 1st
+ if arrInputMatrix[nRowIndx][nColIndx_01] == 0:
+ return False
+
+ ## 2nd
+ if arrInputMatrix[nRowIndx][nColIndx_02] == 0:
+ return False
+
+ ## 3rd
+ for nColIndx in range(nLen):
+ if nColIndx in [nColIndx_01, nColIndx_02]:
+ continue
+
+ if arrInputMatrix[nRowIndx][nColIndx] != 0:
+ return False
+
+ return True
+
+## arrMatrix = [[1, 0, 0, 2], [0, 3, 4, 0], [0, 5, 6, 0], [7, 0, 0, 1]] ## Example 1
+## arrMatrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] ## Example 2
+arrMatrix = [[1, 0, 2], [0, 3, 0], [4, 0, 5]] ## Example 3
+
+print (IsXMatrix (arrMatrix))
diff --git a/challenge-266/perlboy1967/perl/ch1.pl b/challenge-266/perlboy1967/perl/ch-1.pl index f104fec4a6..f104fec4a6 100755 --- a/challenge-266/perlboy1967/perl/ch1.pl +++ b/challenge-266/perlboy1967/perl/ch-1.pl diff --git a/challenge-266/perlboy1967/perl/ch2.pl b/challenge-266/perlboy1967/perl/ch-2.pl index 0526dcd74b..0526dcd74b 100755 --- a/challenge-266/perlboy1967/perl/ch2.pl +++ b/challenge-266/perlboy1967/perl/ch-2.pl diff --git a/challenge-266/reinier-maliepaard/blog.txt b/challenge-266/reinier-maliepaard/blog.txt new file mode 100644 index 0000000000..8cfdaba867 --- /dev/null +++ b/challenge-266/reinier-maliepaard/blog.txt @@ -0,0 +1 @@ +https://reiniermaliepaard.nl/perl/pwc/index.php?id=pwc266 diff --git a/challenge-266/reinier-maliepaard/perl/ch-1.pl b/challenge-266/reinier-maliepaard/perl/ch-1.pl new file mode 100644 index 0000000000..fb4002d6f1 --- /dev/null +++ b/challenge-266/reinier-maliepaard/perl/ch-1.pl @@ -0,0 +1,37 @@ +#!/usr/bin/perl +use strict; +use warnings; +#------------------------------------------- + +sub uncommon_word { + + my($s1, $s2) = @_; + + my %freq; + my @result; + + $freq{$_}++ foreach(split(/ /, $s1)); + $freq{$_}++ foreach(split(/ /, $s2)); + + foreach my $k (keys(%freq)) { + push(@result, "'$k'") if($freq{$k} == 1); + } + print("(", join(", ", @result),")", "\n"); +} + +my ($s1, $s2); + +# Example 1 +$s1 = "Mango is sweet"; +$s2 = "Mango is sour"; +uncommon_word($s1, $s2); # Output: ('sweet', 'sour') + +# Example 2 +$s1 = "Mango Mango"; +$s2 = "Orange"; +uncommon_word($s1, $s2); # Output: ('Orange') + +# Example 3 +$s1 = "Mango is Mango"; +$s2 = "Orange is Orange"; +uncommon_word($s1, $s2); # Output: () diff --git a/challenge-266/reinier-maliepaard/perl/ch-2.pl b/challenge-266/reinier-maliepaard/perl/ch-2.pl new file mode 100644 index 0000000000..40bd456903 --- /dev/null +++ b/challenge-266/reinier-maliepaard/perl/ch-2.pl @@ -0,0 +1,54 @@ +#!/usr/bin/perl +use strict; +use warnings; +#------------------------------------------- + +sub is_x_matrix { + my $matrix = shift; + + my $size = @$matrix; + + # check main diagonal and antidiagonal + for my $i (0 .. $size - 1) { + # check main diagonal + return 0 if ($matrix->[$i][$i] == 0); + # check antidiagonal + return 0 if ($matrix->[$i][$size - 1 - $i] == 0); + } + + # check all other elements + for my $i (0 .. $size - 1) { + for my $j (0 .. $size - 1) { + return 0 if ($i != $j && $i + $j != ($size - 1) && $matrix->[$i][$j] != 0); + } + } + + # it's an X Matrix + return 1; +} + +# TESTS + +my $matrix; + +# Example 1 +$matrix = [ [1, 0, 0, 2], + [0, 3, 4, 0], + [0, 5, 6, 0], + [7, 0, 0, 1], + ]; +print(is_x_matrix($matrix), "\n"); # Output: 1 + +# Example 2 +$matrix = [ [1, 2, 3], + [4, 5, 6], + [7, 8, 9], + ]; +print(is_x_matrix($matrix), "\n"); # Output: 0 + +# Example 3 +$matrix = [ [1, 0, 2], + [0, 3, 0], + [4, 0, 5], + ]; +print(is_x_matrix($matrix), "\n"); # Output: 1 diff --git a/stats/pwc-challenge-017.json b/stats/pwc-challenge-017.json index 1151253dd3..c55bcc5a45 100644 --- a/stats/pwc-challenge-017.json +++ b/stats/pwc-challenge-017.json @@ -1,182 +1,12 @@ { - "subtitle" : { - "text" : "[Champions: 31] Last updated at 2023-03-26 10:37:55 GMT" - }, - "chart" : { - "type" : "column" - }, - "yAxis" : { - "title" : { - "text" : "Total Solutions" - } - }, - "series" : [ - { - "colorByPoint" : 1, - "name" : "The Weekly Challenge - 017", - "data" : [ - { - "drilldown" : "Adam Russell", - "name" : "Adam Russell", - "y" : 4 - }, - { - "name" : "Andrezgz", - "y" : 2, - "drilldown" : "Andrezgz" - }, - { - "y" : 3, - "name" : "Arne Sommer", - "drilldown" : "Arne Sommer" - }, - { - "y" : 4, - "name" : "Athanasius", - "drilldown" : "Athanasius" - }, - { - "drilldown" : "Daniel Mantovani", - "y" : 2, - "name" : "Daniel Mantovani" - }, - { - "drilldown" : "Dave Jacoby", - "name" : "Dave Jacoby", - "y" : 3 - }, - { - "drilldown" : "Duane Powell", - "y" : 2, - "name" : "Duane Powell" - }, - { - "name" : "Duncan C. White", - "y" : 2, - "drilldown" : "Duncan C. White" - }, - { - "name" : "E. Choroba", - "y" : 3, - "drilldown" : "E. Choroba" - }, - { - "drilldown" : "Feng Chang", - "name" : "Feng Chang", - "y" : 4 - }, - { - "drilldown" : "Francis Whittle", - "y" : 3, - "name" : "Francis Whittle" - }, - { - "drilldown" : "Jaldhar H. Vyas", - "name" : "Jaldhar H. Vyas", - "y" : 6 - }, - { - "y" : 6, - "name" : "Joelle Maslak", - "drilldown" : "Joelle Maslak" - }, - { - "y" : 2, - "name" : "Jorg Sommrey", - "drilldown" : "Jorg Sommrey" - }, - { - "drilldown" : "Kevin Colyer", - "name" : "Kevin Colyer", - "y" : 2 - }, - { - "y" : 3, - "name" : "Kian-Meng Ang", - "drilldown" : "Kian-Meng Ang" - }, - { - "drilldown" : "Lakpa Tashi Bhutia", - "name" : "Lakpa Tashi Bhutia", - "y" : 1 - }, - { - "drilldown" : "Laurent Rosenfeld", - "y" : 6, - "name" : "Laurent Rosenfeld" - }, - { - "name" : "Lubos Kolouch", - "y" : 2, - "drilldown" : "Lubos Kolouch" - }, - { - "drilldown" : "Michael Hamlin", - "name" : "Michael Hamlin", - "y" : 1 - }, - { - "drilldown" : "Noud Aldenhoven", - "name" : "Noud Aldenhoven", - "y" : 2 - }, - { - "y" : 1, - "name" : "Ozzy", - "drilldown" : "Ozzy" - }, - { - "name" : "Paulo Custodio", - "y" : 2, - "drilldown" : "Paulo Custodio" - }, - { - "drilldown" : "Randy Lauen", - "name" : "Randy Lauen", - "y" : 1 - }, - { - "name" : "Roger Bell_West", - "y" : 2, - "drilldown" : "Roger Bell_West" - }, - { - "drilldown" : "Ruben Westerberg", - "name" : "Ruben Westerberg", - "y" : 4 - }, - { - "name" : "Simon Proctor", - "y" : 1, - "drilldown" : "Simon Proctor" - }, - { - "drilldown" : "Steven Wilson", - "y" : 2, - "name" : "Steven Wilson" - }, - { - "y" : 2, - "name" : "Stuart Little", - "drilldown" : "Stuart Little" - }, - { - "drilldown" : "Veesh Goldman", - "name" : "Veesh Goldman", - "y" : 4 - }, - { - "drilldown" : "Yozen Hernandez", - "name" : "Yozen Hernandez", - "y" : 4 - } - ] + "plotOptions" : { + "series" : { + "dataLabels" : { + "enabled" : 1, + "format" : "{point.y}" + }, + "borderWidth" : 0 } - ], - "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/>" }, "drilldown" : { "series" : [ @@ -196,13 +26,13 @@ }, { "name" : "Andrezgz", - "id" : "Andrezgz", "data" : [ [ "Perl", 2 ] - ] + ], + "id" : "Andrezgz" }, { "id" : "Arne Sommer", @@ -239,10 +69,11 @@ 2 ] ], - "id" : "Daniel Mantovani", - "name" : "Daniel Mantovani" + "name" : "Daniel Mantovani", + "id" : "Daniel Mantovani" }, { + "name" : "Dave Jacoby", "data" : [ [ "Perl", @@ -253,30 +84,41 @@ 1 ] ], - "id" : "Dave Jacoby", - "name" : "Dave Jacoby" + "id" : "Dave Jacoby" }, { "data" : [ [ "Perl", - 2 + 1 ] ], + "name" : "David Ferrone", + "id" : "David Ferrone" + }, + { "name" : "Duane Powell", + "data" : [ + [ + "Perl", + 2 + ] + ], "id" : "Duane Powell" }, { - "id" : "Duncan C. White", - "name" : "Duncan C. White", "data" : [ [ "Perl", 2 ] - ] + ], + "name" : "Duncan C. White", + "id" : "Duncan C. White" }, { + "id" : "E. Choroba", + "name" : "E. Choroba", "data" : [ [ "Perl", @@ -286,11 +128,10 @@ "Blog", 1 ] - ], - "id" : "E. Choroba", - "name" : "E. Choroba" + ] }, { + "id" : "Feng Chang", "data" : [ [ "Perl", @@ -301,12 +142,9 @@ 2 ] ], - "id" : "Feng Chang", "name" : "Feng Chang" }, { - "name" : "Francis Whittle", - "id" : "Francis Whittle", "data" : [ [ "Raku", @@ -316,11 +154,12 @@ "Blog", 1 ] - ] + ], + "name" : "Francis Whittle", + "id" : "Francis Whittle" }, { "name" : "Jaldhar H. Vyas", - "id" : "Jaldhar H. Vyas", "data" : [ [ "Perl", @@ -334,11 +173,12 @@ "Blog", 1 ] - ] + ], + "id" : "Jaldhar H. Vyas" }, { - "name" : "Joelle Maslak", "id" : "Joelle Maslak", + "name" : "Joelle Maslak", "data" : [ [ "Perl", @@ -357,20 +197,21 @@ 2 ] ], - "id" : "Jorg Sommrey", - "name" : "Jorg Sommrey" + "name" : "Jorg Sommrey", + "id" : "Jorg Sommrey" }, { + "name" : "Kevin Colyer", "data" : [ [ "Raku", 2 ] ], - "id" : "Kevin Colyer", - "name" : "Kevin Colyer" + "id" : "Kevin Colyer" }, { + "id" : "Kian-Meng Ang", "data" : [ [ "Perl", @@ -381,8 +222,7 @@ 1 ] ], - "name" : "Kian-Meng Ang", - "id" : "Kian-Meng Ang" + "name" : "Kian-Meng Ang" }, { "data" : [ @@ -391,8 +231,8 @@ 1 ] ], - "id" : "Lakpa Tashi Bhutia", - "name" : "Lakpa Tashi Bhutia" + "name" : "Lakpa Tashi Bhutia", + "id" : "Lakpa Tashi Bhutia" }, { "data" : [ @@ -413,28 +253,28 @@ "id" : "Laurent Rosenfeld" }, { + "id" : "Lubos Kolouch", + "name" : "Lubos Kolouch", "data" : [ [ "Perl", 2 ] - ], - "name" : "Lubos Kolouch", - "id" : "Lubos Kolouch" + ] }, { + "id" : "Michael Hamlin", + "name" : "Michael Hamlin", "data" : [ [ "Perl", 1 ] - ], - "name" : "Michael Hamlin", - "id" : "Michael Hamlin" + ] }, { - "name" : "Noud Aldenhoven", "id" : "Noud Aldenhoven", + "name" : "Noud Aldenhoven", "data" : [ [ "Raku", @@ -443,28 +283,28 @@ ] }, { + "name" : "Ozzy", "data" : [ [ "Raku", 1 ] ], - "id" : "Ozzy", - "name" : "Ozzy" + "id" : "Ozzy" }, { + "id" : "Paulo Custodio", "data" : [ [ "Perl", 2 ] ], - "name" : "Paulo Custodio", - "id" : "Paulo Custodio" + "name" : "Paulo Custodio" }, { - "name" : "Randy Lauen", "id" : "Randy Lauen", + "name" : "Randy Lauen", "data" : [ [ "Raku", @@ -473,18 +313,18 @@ ] }, { + "id" : "Roger Bell_West", "data" : [ [ "Perl", 2 ] ], - "id" : "Roger Bell_West", "name" : "Roger Bell_West" }, { - "name" : "Ruben Westerberg", "id" : "Ruben Westerberg", + "name" : "Ruben Westerberg", "data" : [ [ "Perl", @@ -498,36 +338,35 @@ }, { "name" : "Simon Proctor", - "id" : "Simon Proctor", "data" : [ [ "Raku", 1 ] - ] + ], + "id" : "Simon Proctor" }, { + "name" : "Steven Wilson", "data" : [ [ "Perl", 2 ] ], - "id" : "Steven Wilson", - "name" : "Steven Wilson" + "id" : "Steven Wilson" }, { - "name" : "Stuart Little", "id" : "Stuart Little", "data" : [ [ "Raku", 2 ] - ] + ], + "name" : "Stuart Little" }, { - "name" : "Veesh Goldman", "id" : "Veesh Goldman", "data" : [ [ @@ -542,9 +381,11 @@ "Blog", 1 ] - ] + ], + "name" : "Veesh Goldman" }, { + "name" : "Yozen Hernandez", "data" : [ [ "Perl", @@ -555,26 +396,200 @@ 2 ] ], - "name" : "Yozen Hernandez", "id" : "Yozen Hernandez" } ] }, + "series" : [ + { + "colorByPoint" : 1, + "data" : [ + { + "y" : 4, + "drilldown" : "Adam Russell", + "name" : "Adam Russell" + }, + { + "y" : 2, + "drilldown" : "Andrezgz", + "name" : "Andrezgz" + }, + { + "name" : "Arne Sommer", + "drilldown" : "Arne Sommer", + "y" : 3 + }, + { + "name" : "Athanasius", + "drilldown" : "Athanasius", + "y" : 4 + }, + { + "name" : "Daniel Mantovani", + "drilldown" : "Daniel Mantovani", + "y" : 2 + }, + { + "y" : 3, + "drilldown" : "Dave Jacoby", + "name" : "Dave Jacoby" + }, + { + "name" : "David Ferrone", + "y" : 1, + "drilldown" : "David Ferrone" + }, + { + "drilldown" : "Duane Powell", + "y" : 2, + "name" : "Duane Powell" + }, + { + "drilldown" : "Duncan C. White", + "y" : 2, + "name" : "Duncan C. White" + }, + { + "drilldown" : "E. Choroba", + "y" : 3, + "name" : "E. Choroba" + }, + { + "name" : "Feng Chang", + "y" : 4, + "drilldown" : "Feng Chang" + }, + { + "drilldown" : "Francis Whittle", + "y" : 3, + "name" : "Francis Whittle" + }, + { + "y" : 6, + "drilldown" : "Jaldhar H. Vyas", + "name" : "Jaldhar H. Vyas" + }, + { + "y" : 6, + "drilldown" : "Joelle Maslak", + "name" : "Joelle Maslak" + }, + { + "y" : 2, + "drilldown" : "Jorg Sommrey", + "name" : "Jorg Sommrey" + }, + { + "name" : "Kevin Colyer", + "drilldown" : "Kevin Colyer", + "y" : 2 + }, + { + "y" : 3, + "drilldown" : "Kian-Meng Ang", + "name" : "Kian-Meng Ang" + }, + { + "y" : 1, + "drilldown" : "Lakpa Tashi Bhutia", + "name" : "Lakpa Tashi Bhutia" + }, + { + "name" : "Laurent Rosenfeld", + "drilldown" : "Laurent Rosenfeld", + "y" : 6 + }, + { + "name" : "Lubos Kolouch", + "y" : 2, + "drilldown" : "Lubos Kolouch" + }, + { + "y" : 1, + "drilldown" : "Michael Hamlin", + "name" : "Michael Hamlin" + }, + { + "name" : "Noud Aldenhoven", + "drilldown" : "Noud Aldenhoven", + "y" : 2 + }, + { + "name" : "Ozzy", + "drilldown" : "Ozzy", + "y" : 1 + }, + { + "name" : "Paulo Custodio", + "y" : 2, + "drilldown" : "Paulo Custodio" + }, + { + "name" : "Randy Lauen", + "y" : 1, + "drilldown" : "Randy Lauen" + }, + { + "name" : "Roger Bell_West", + "y" : 2, + "drilldown" : "Roger Bell_West" + }, + { + "y" : 4, + "drilldown" : "Ruben Westerberg", + "name" : "Ruben Westerberg" + }, + { + "name" : "Simon Proctor", + "y" : 1, + "drilldown" : "Simon Proctor" + }, + { + "y" : 2, + "drilldown" : "Steven Wilson", + "name" : "Steven Wilson" + }, + { + "name" : "Stuart Little", + "drilldown" : "Stuart Little", + "y" : 2 + }, + { + "name" : "Veesh Goldman", + "drilldown" : "Veesh Goldman", + "y" : 4 + }, + { + "y" : 4, + "drilldown" : "Yozen Hernandez", + "name" : "Yozen Hernandez" + } + ], + "name" : "The Weekly Challenge - 017" + } + ], "legend" : { "enabled" : 0 }, - "plotOptions" : { - "series" : { - "dataLabels" : { - "enabled" : 1, - "format" : "{point.y}" - }, - "borderWidth" : 0 - } + "chart" : { + "type" : "column" }, "title" : { "text" : "The Weekly Challenge - 017" }, + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } + }, + "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/>" + }, + "subtitle" : { + "text" : "[Champions: 32] Last updated at 2024-04-23 15:59:07 GMT" + }, "xAxis" : { "type" : "category" } diff --git a/stats/pwc-challenge-018.json b/stats/pwc-challenge-018.json index fc2a57d9af..c6b1a090b8 100644 --- a/stats/pwc-challenge-018.json +++ b/stats/pwc-challenge-018.json @@ -1,188 +1,18 @@ { - "legend" : { - "enabled" : 0 - }, - "tooltip" : { - "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b>&l |
