diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-05-16 12:41:34 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-05-16 12:41:34 +0100 |
| commit | 15aa8637d53cf3eb5d99b6167a73ad477cd9f467 (patch) | |
| tree | 07d0303ae221586405a962edd6a81b8fc4e4b81a | |
| parent | 419671d52a4e51f6bd4d85625cf7eeb98e3456d8 (diff) | |
| download | perlweeklychallenge-club-15aa8637d53cf3eb5d99b6167a73ad477cd9f467.tar.gz perlweeklychallenge-club-15aa8637d53cf3eb5d99b6167a73ad477cd9f467.tar.bz2 perlweeklychallenge-club-15aa8637d53cf3eb5d99b6167a73ad477cd9f467.zip | |
- Added solutions by Niels van Dijke.
- Added solutions by Peter Campbell Smith.
- Added solutions by Mark Anderson.
- Added solutions by Ali Moradi.
- Added solutions by David Ferrone.
- Added solutions by Leo Manfredi.
- Added solutions by W. Luis Mochan.
- Added solutions by Thomas Kohler.
- Added solutions by Stephen G. Lynn.
- Added solutions by Robert DiCicco.
30 files changed, 3457 insertions, 2785 deletions
diff --git a/challenge-217/eric-cheung/python/ch-1.py b/challenge-217/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..5e86bfde73 --- /dev/null +++ b/challenge-217/eric-cheung/python/ch-1.py @@ -0,0 +1,14 @@ +
+import numpy as np
+
+## arrMatrix = np.array([[3, 1, 2], [5, 2, 4], [0, 1, 3]]) ## Example 1
+## arrMatrix = np.array([[2, 1], [4, 5]]) ## Example 2
+arrMatrix = np.array([[1, 0, 3], [0, 0, 0], [1, 2, 1]]) ## Example 3
+
+arrList = arrMatrix.flatten()
+arrList.sort()
+
+if len(arrList) >= 3:
+ print (arrList[2])
+else:
+ print (0)
diff --git a/challenge-217/eric-cheung/python/ch-2.py b/challenge-217/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..e1ea9d96d0 --- /dev/null +++ b/challenge-217/eric-cheung/python/ch-2.py @@ -0,0 +1,19 @@ +
+from itertools import permutations
+
+## arrList = [1, 23] ## Example 1
+## arrList = [10, 3, 2] ## Example 2
+## arrList = [31, 2, 4, 10] ## Example 3
+## arrList = [5, 11, 4, 1, 2] ## Example 4
+arrList = [1, 10] ## Example 5
+
+arrPerm = permutations(arrList)
+
+nMax = 0
+
+for arrLoop in arrPerm:
+ strTempNum = "".join([str(nElemLoop) for nElemLoop in arrLoop])
+ if int(strTempNum) > nMax:
+ nMax = int(strTempNum)
+
+print (nMax)
diff --git a/challenge-217/jeanluc2020/blog-1.txt b/challenge-217/jeanluc2020/blog.txt index 6d650ff709..6d650ff709 100644 --- a/challenge-217/jeanluc2020/blog-1.txt +++ b/challenge-217/jeanluc2020/blog.txt diff --git a/challenge-217/jeanluc2020/blog-2.txt b/challenge-217/jeanluc2020/blog1.txt index 8505a12af1..8505a12af1 100644 --- a/challenge-217/jeanluc2020/blog-2.txt +++ b/challenge-217/jeanluc2020/blog1.txt diff --git a/challenge-217/perlboy1967/perl/ch1.pl b/challenge-217/perlboy1967/perl/ch-1.pl index 5de8809b9b..5de8809b9b 100755 --- a/challenge-217/perlboy1967/perl/ch1.pl +++ b/challenge-217/perlboy1967/perl/ch-1.pl diff --git a/challenge-217/perlboy1967/perl/ch2.pl b/challenge-217/perlboy1967/perl/ch-2.pl index 60d238fdf7..60d238fdf7 100755 --- a/challenge-217/perlboy1967/perl/ch2.pl +++ b/challenge-217/perlboy1967/perl/ch-2.pl diff --git a/challenge-217/robert-dicicco/julia/ch-1.jl b/challenge-217/robert-dicicco/julia/ch-1.jl new file mode 100644 index 0000000000..7bfd1de831 --- /dev/null +++ b/challenge-217/robert-dicicco/julia/ch-1.jl @@ -0,0 +1,68 @@ +#!/usr/bin/env julia +#= +-------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-05-15 +Challenge 217 Sorted Matrix ( Julia ) +-------------------------------------- +=# +using Printf + +function checkArgs(args) + global arg + try + arg = parse(Int64, args[1]) + catch + println("Error: Argument must be an integer") + exit(0) + finally + main(arg) + end +end + + +matrix = [] +out = [] + +function main(arg) + global matrix, out + if arg == 0 + matrix = [[3,1,2],[5,2,4],[0,1,3]] + elseif arg == 1 + matrix = [[2,1], [4,5]] + #println(matrix) + elseif arg == 2 + matrix = [[1,0,3],[0,0,0],[ 1,2,1]]; + #println(matrix) + else + println("Error! arg must be between 0 and 2 inclusive") + end + @printf("Input: @matrix = %s\n",matrix) + for arr in matrix + for val in arr + push!(out, val) + end + end + @printf("%s\n",sort(out)[3]) +end + +checkArgs(ARGS) + +#= +-------------------------------------- +SAMPLE OUTPUT +julia .\SortedMatrix.jl 0 +Input: @matrix = [[3, 1, 2], [5, 2, 4], [0, 1, 3]] +1 + +PS G:\Projects\Perl\Challenges> julia .\SortedMatrix.jl 1 +Input: @matrix = [[2, 1], [4, 5]] +4 + +PS G:\Projects\Perl\Challenges> julia .\SortedMatrix.jl 2 +Input: @matrix = [[1, 0, 3], [0, 0, 0], [1, 2, 1]] +0 +-------------------------------------- +=# + + diff --git a/challenge-217/robert-dicicco/perl/ch-1.pl b/challenge-217/robert-dicicco/perl/ch-1.pl new file mode 100644 index 0000000000..c61474a0df --- /dev/null +++ b/challenge-217/robert-dicicco/perl/ch-1.pl @@ -0,0 +1,59 @@ +#!/usr/bin/env perl +=begin comment +-------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-05-15 +Challenge 217 Sorted Matrix ( Perl ) +-------------------------------------- +=cut + +use strict; +use warnings; +use feature 'say'; + +my @matrix = (); +my $array = $ARGV[0]; +if ($array < 0 or $array > 2) { say "Error! arg must be between 0 and 2 inclusive";exit}; + +if ($array == 0) { + @matrix = ((3, 1, 2), (5, 2, 4), (0, 1, 3)); +} elsif ($array == 1) { + @matrix = ((2, 1), (4, 5)); +} elsif ($array == 2) { + @matrix = ((1, 0, 3), (0, 0, 0), (1, 2, 1)); +} else { + # should never get here! +} + +my @out = (); + + +print "Input: \@matrix = "; +for (@matrix) { + print "$_"; + for my $val ($_) { + push(@out, $val); + } +} +say " "; +@out = sort(@out); +say "Output: $out[2]"; + +=begin comment +-------------------------------------- +SAMPLE OUTPUT +perl .\SortedMatrix.pl 0 +Input: @matrix = 312524013 +Output: 1 + +PS G:\Projects\Perl\Challenges> perl .\SortedMatrix.pl 1 +Input: @matrix = 2145 +Output: 4 + +PS G:\Projects\Perl\Challenges> perl .\SortedMatrix.pl 2 +Input: @matrix = 103000121 +Output: 0 +-------------------------------------- +=cut + + diff --git a/challenge-217/robert-dicicco/perl/ch-2.pl b/challenge-217/robert-dicicco/perl/ch-2.pl new file mode 100644 index 0000000000..8055b78118 --- /dev/null +++ b/challenge-217/robert-dicicco/perl/ch-2.pl @@ -0,0 +1,51 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use feature 'say'; +use Algorithm::Permute; +=begin comment +--------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-05-15 +Challenge 217 Max Number ( Perl ) +--------------------------------------- +=cut + +my @list = ([5,11,4,1,2],[31, 2, 4,10],[10,3,2],[1, 23],[1,10]); +my $max = 0; + +for my $lst (@list) { + print("Input: \@list = [@$lst]\n"); + my $p_iterator = Algorithm::Permute->new ( $lst ); + while (my @perm = $p_iterator->next) { + my $num = join("",@perm); + if ($num > $max) { + $max = $num; + } + } + print("Output: $max\n\n"); + $max = 0; +} + +=begin comment +--------------------------------------- +SAMPLE OUTPUT +perl MaxNumber.pl +Input: @list = [5 11 4 1 2] +Output: 542111 + +Input: @list = [31 2 4 10] +Output: 431210 + +Input: @list = [10 3 2] +Output: 3210 + +Input: @list = [1 23] +Output: 231 + +Input: @list = [1 10] +Output: 110 +--------------------------------------- +=cut + + diff --git a/challenge-217/robert-dicicco/python/ch-1.py b/challenge-217/robert-dicicco/python/ch-1.py new file mode 100644 index 0000000000..7ef01fac80 --- /dev/null +++ b/challenge-217/robert-dicicco/python/ch-1.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python +# -------------------------------------- +# AUTHOR: Robert DiCicco +# DATE : 2023-05-15 +# Challenge 217 Sorted Matrix ( Python ) +# -------------------------------------- + +matrix = [[3,1,2],[5,2,4],[0,1,3]], [[2,1], [4,5]], [[1,0,3],[0,0,0],[ 1,2,1]] + +for mat in matrix: + out = [] + print("Input: @matrix = ",mat) + for arr in mat: + for num in arr: + out.append(num) + out.sort() + print("out = ",out[2]) + print(" ") + + +# ------------------------------------- +# SAMPLE OUTPUT +# python .\SortedMatrix.py +# Input: @matrix = [[3, 1, 2], [5, 2, 4], [0, 1, 3]] +# out = 1 + +# Input: @matrix = [[2, 1], [4, 5]] +# out = 4 + +# Input: @matrix = [[1, 0, 3], [0, 0, 0], [1, 2, 1]] +# out = 0 +# ------------------------------------- + + diff --git a/challenge-217/robert-dicicco/raku/ch-1.raku b/challenge-217/robert-dicicco/raku/ch-1.raku new file mode 100644 index 0000000000..faa15be764 --- /dev/null +++ b/challenge-217/robert-dicicco/raku/ch-1.raku @@ -0,0 +1,30 @@ +#!/usr/bin/env raku +use v6; +=begin comment +-------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-05-15 +Challenge 217 Sorted Matrix ( Perl ) +-------------------------------------- +=end comment + +my @matrix = <3 1 2 5 2 4 0 1 3>,<2 1 4 5>,<1 0 3 0 0 0 1 2 1>; + +for (@matrix) -> @sub { + say "Input: \@matrix = ",@sub; + say "Output: ", @sub.sort[2]; +} +=begin comment +-------------------------------------- +SAMPLE OUTPUT +raku SortedMatrix.rk +Input: @matrix = (3 1 2 5 2 4 0 1 3) +Output: 1 + +Input: @matrix = (2 1 4 5) +Output: 4 + +Input: @matrix = (1 0 3 0 0 0 1 2 1) +Output: 0 +-------------------------------------- +=end comment diff --git a/challenge-217/robert-dicicco/raku/ch-2.raku b/challenge-217/robert-dicicco/raku/ch-2.raku new file mode 100644 index 0000000000..0864872144 --- /dev/null +++ b/challenge-217/robert-dicicco/raku/ch-2.raku @@ -0,0 +1,48 @@ +#!/usr/bin/env raku +use v6; +=begin comment +--------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-05-15 +Challenge 217 Max Number ( Raku ) +--------------------------------------- +=end comment + + +my @list = ([5,11,4,1,2],[31, 2, 4,10],[10,3,2],[1, 23],[1,10]); +my $max = 0; + +for (@list) -> @lst { + print("Input: @list = ",@lst,"\n"); + for @lst.permutations -> $p { + my $num = $p.join; + if $num > $max { + $max = $num; + } + } + say "Output: $max\n"; + $max = 0; +} + +=begin comment +--------------------------------------- +SAMPLE OUTPUT +raku MaxNumber.rk +Input: @list = 5 11 4 1 2 +Output: 542111 + +Input: @list = 31 2 4 10 +Output: 431210 + +Input: @list = 10 3 2 +Output: 3210 + +Input: @list = 1 23 +Output: 231 + +Input: @list = 1 10 +Output: 110 +--------------------------------------- +=end comment + + diff --git a/challenge-217/robert-dicicco/ruby/ch-1.rb b/challenge-217/robert-dicicco/ruby/ch-1.rb new file mode 100644 index 0000000000..5602546510 --- /dev/null +++ b/challenge-217/robert-dicicco/ruby/ch-1.rb @@ -0,0 +1,55 @@ +#!/usr/bin/env ruby +=begin comment +-------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-05-15 +Challenge 217 Sorted Matrix ( Ruby ) +-------------------------------------- +=end comment +arg = ARGV[0].to_i +if ARGV.length == 0 + puts("Error! arg must be between 0 and 2 inclusive") + exit +end + + +if arg < 0 or arg > 2 + puts("Error! arg must be between 0 and 2 inclusive") + exit +end +case arg +when 0 + matrix = [[3,1,2],[5,2,4],[0,1,3]] +when 1 + matrix = [[2,1], [4,5]] +when 2 + matrix = [[1,0,3],[0,0,0],[ 1,2,1]]; +end +out = [] +puts("Input @matrix = #{matrix}") +matrix.each do |arr| + arr.each do |val| + out.push(val) + end +end +puts("Output: #{out.sort![2]}") +puts(" ") + +=begin comment +-------------------------------------- +SAMPLE OUTPUT +ruby .\SortedMatrix.rb 0 +Input @matrix = [[3, 1, 2], [5, 2, 4], [0, 1, 3]] +Output: 1 + +PS G:\Projects\Perl\Challenges> ruby .\SortedMatrix.rb 1 +Input @matrix = [[2, 1], [4, 5]] +Output: 4 + +PS G:\Projects\Perl\Challenges> ruby .\SortedMatrix.rb 2 +Input @matrix = [[1, 0, 3], [0, 0, 0], [1, 2, 1]] +Output: 0 +-------------------------------------- +=end comment + + diff --git a/challenge-217/robert-dicicco/ruby/ch-2.rb b/challenge-217/robert-dicicco/ruby/ch-2.rb new file mode 100644 index 0000000000..e60f8d704a --- /dev/null +++ b/challenge-217/robert-dicicco/ruby/ch-2.rb @@ -0,0 +1,49 @@ +#!/usr/bin/env ruby +=begin +--------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-05-15 +Challenge 217 Max Number ( Ruby ) +--------------------------------------- +=end + +list = [[5,11,4,1,2],[31, 2, 4,10],[10,3,2],[1, 23],[1,10]]; +max = 0 + +list.each do |lst| + puts("Input: @list = #{lst}") + ln = lst.length() + lst.permutation(ln) do |item| + n = (item.join).to_i + if n > max + max = n + end + end + puts("Output: #{max}") + puts("") + max = 0 +end + +=begin +--------------------------------------- +SAMPLE OUTPUT +ruby MaxNumber.rb +Input: @list = [5, 11, 4, 1, 2] +Output: 542111 + +Input: @list = [31, 2, 4, 10] +Output: 431210 + +Input: @list = [10, 3, 2] +Output: 3210 + +Input: @list = [1, 23] +Output: 231 + +Input: @list = [1, 10] +Output: 110 +--------------------------------------- +=end + + + diff --git a/stats/pwc-challenge-216.json b/stats/pwc-challenge-216.json new file mode 100644 index 0000000000..27723919f8 --- /dev/null +++ b/stats/pwc-challenge-216.json @@ -0,0 +1,593 @@ +{ + "title" : { + "text" : "The Weekly Challenge - 216" + }, + "legend" : { + "enabled" : 0 + }, + "drilldown" : { + "series" : [ + { + "name" : "Arne Sommer", + "data" : [ + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Arne Sommer" + }, + { + "id" : "Avery Adams", + "data" : [ + [ + "Perl", + 1 + ], + [ + "Blog", + 2 + ] + ], + "name" : "Avery Adams" + }, + { + "name" : "BarrOff", + "data" : [ + [ + "Raku", + 1 + ] + ], + "id" : "BarrOff" + }, + { + "id" : "Bruce Gray", + "data" : [ + [ + "Raku", + 2 + ] + ], + "name" : "Bruce Gray" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "name" : "David Ferrone", + "id" : "David Ferrone" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "name" : "Duncan C. White", + "id" : "Duncan C. White" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "name" : "E. Choroba", + "id" : "E. Choroba" + }, + { + "id" : "Feng Chang", + "name" : "Feng Chang", + "data" : [ + [ + "Raku", + 2 + ] + ] + }, + { + "name" : "Flavio Poletti", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ], + [ + "Blog", + 2 + ] + ], + "id" : "Flavio Poletti" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ], + "name" : "Jaldhar H. Vyas", + "id" : "Jaldhar H. Vyas" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "name" : "James Smith", + "id" : "James Smith" + }, + { + "id" : "Jan Krnavek", + "data" : [ + [ + "Raku", + 1 + ] + ], + "name" : "Jan Krnavek" + }, + { + "id" : "Jorg Sommrey", + "name" : "Jorg Sommrey", + "data" : [ + [ + "Perl", + 1 + ] + ] + }, + { + "name" : "Laurent Rosenfeld", + "data" : [ + [ + "Perl", + 1 + ], + [ + "Raku", + 1 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Laurent Rosenfeld" + }, + { + "data" : [ + [ + "Perl", + 1 + ] + ], + "name" : "Leo Manfredi", + "id" : "Leo Manfredi" + }, + { + "name" : "Lubos Kolouch", + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Lubos Kolouch" + }, + { + "id" : "Luca Ferrari", + "data" : [ + [ + "Raku", + 2 + ], + [ + "Blog", + 6 + ] + ], + "name" : "Luca Ferrari" + }, + { + "data" : [ + [ + "Raku", + 2 + ] + ], + "name" : "Mark Anderson", + "id" : "Mark Anderson" + }, + { + "name" : "Matthias Muth", + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Matthias Muth" + }, + { + "id" : "Niels van Dijke", + "data" : [ + [ + "Perl", + 1 + ] + ], + "name" : "Niels van Dijke" + }, + { + "id" : "Peter Campbell Smith", + "name" : "Peter Campbell Smith", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ] + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "name" : "RibTips", + "id" : "RibTips" + }, + { + "id" : "Robbie Hatley", + "name" : "Robbie Hatley", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ] + }, + { + "data" : [ + [ + "Perl", + 1 + ], + [ + "Raku", + 1 + ] + ], + "name" : "Robert DiCicco", + "id" : "Robert DiCicco" + }, + { + "id" : "Roger Bell_West", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ], + "name" : "Roger Bell_West" + }, + { + "id" : "Shimon Bollinger", + "data" : [ + [ + "Raku", + 1 + ], + [ + "Blog", + 1 + ] + ], + "name" : "Shimon Bollinger" + }, + { + "name" : "Simon Green", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Simon Green" + }, + { + "data" : [ + [ + "Perl", + 1 + ] + ], + "name" : "Solathian", + "id" : "Solathian" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 2 + ] + ], + "name" : "Thomas Kohler", + "id" : "Thomas Kohler" + }, + { + "id" : "Ulrich Rieke", + "name" : "Ulrich Rieke", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 1 + ] + ] + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "name" : "W. Luis Mochan", + "id" : "W. Luis Mochan" + } + ] + }, + "chart" : { + "type" : "column" + }, + "subtitle" : { + "text" : "[Champions: 31] Last updated at 2023-05-16 11:28:38 GMT" + }, + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } + }, + "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/>" + }, + "plotOptions" : { + "series" : { + "borderWidth" : 0, + "dataLabels" : { + "format" : "{point.y}", + "enabled" : 1 + } + } + }, + "series" : [ + { + "colorByPoint" : 1, + "data" : [ + { + "name" : "Arne Sommer", + "y" : 3, + "drilldown" : "Arne Sommer" + }, + { + "drilldown" : "Avery Adams", + "y" : 3, + "name" : "Avery Adams" + }, + { + "name" : "BarrOff", + "y" : 1, + |
