diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-05-23 19:56:21 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-05-23 19:56:21 +0100 |
| commit | f88ec70a8f56f1d4e7ecf28b0062d46b82f8b030 (patch) | |
| tree | e97b3042d70c219ae232b875b629faab892b4244 | |
| parent | a0378812481339d92fae9464fbd9e98bcca04ff5 (diff) | |
| download | perlweeklychallenge-club-f88ec70a8f56f1d4e7ecf28b0062d46b82f8b030.tar.gz perlweeklychallenge-club-f88ec70a8f56f1d4e7ecf28b0062d46b82f8b030.tar.bz2 perlweeklychallenge-club-f88ec70a8f56f1d4e7ecf28b0062d46b82f8b030.zip | |
- Added solutions by Mark Anderson.
- Added solutions by Stephen G. Lynn.
- Added solutions by David Ferrone.
- Added solutions by Thomas Kohler.
- Added solutions by Niels van Dijke.
- Added solutions by W. Luis Mochan.
- Added solutions by Steven Wilson.
- Added solutions by Robert DiCicco.
- Added solutions by Lubos Kolouch.
29 files changed, 4050 insertions, 3509 deletions
diff --git a/challenge-218/jeanluc2020/blog-1.txt b/challenge-218/jeanluc2020/blog.txt index c669294ffe..c669294ffe 100644 --- a/challenge-218/jeanluc2020/blog-1.txt +++ b/challenge-218/jeanluc2020/blog.txt diff --git a/challenge-218/jeanluc2020/blog-2.txt b/challenge-218/jeanluc2020/blog1.txt index f9b28f55a1..f9b28f55a1 100644 --- a/challenge-218/jeanluc2020/blog-2.txt +++ b/challenge-218/jeanluc2020/blog1.txt diff --git a/challenge-218/perlboy1967/perl/ch1.pl b/challenge-218/perlboy1967/perl/ch-1.pl index 48bbc2aa76..48bbc2aa76 100755 --- a/challenge-218/perlboy1967/perl/ch1.pl +++ b/challenge-218/perlboy1967/perl/ch-1.pl diff --git a/challenge-218/perlboy1967/perl/ch2.pl b/challenge-218/perlboy1967/perl/ch-2.pl index 757630f319..757630f319 100755 --- a/challenge-218/perlboy1967/perl/ch2.pl +++ b/challenge-218/perlboy1967/perl/ch-2.pl diff --git a/challenge-218/robert-dicicco/julia/ch-1.jl b/challenge-218/robert-dicicco/julia/ch-1.jl new file mode 100644 index 0000000000..7157d8e48d --- /dev/null +++ b/challenge-218/robert-dicicco/julia/ch-1.jl @@ -0,0 +1,55 @@ +#!/usr/bin/env julia +#= +----------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-05-22 +Challenge 218 Maximum Product ( Julia ) +----------------------------------------- +=# +using Printf +using Combinatorics + +lists = [[3, 1, 2],[4, 1, 3, 2],[-1, 0, 1, 3, 1],[-8, 2, -9, 0, -4, 3]] + +maxthree = [] + +for lst in lists + global maxthree + maxval = 0 + @printf("Input: @list = %s\n", lst) + for c in combinations(lst,3) + prod = c[1] * c[2] * c[3] + if prod > maxval + maxval = prod + maxthree = sort(c) + end + end + @printf("Output: %d\n",maxval) + @printf("%d x %d x %d = %d\n", maxthree[1],maxthree[2],maxthree[3],maxval) + println("----------------------") +end + +#= +----------------------------------------- +SAMPLE OUTPUT +julia .\MaxProduct.jl + +Input: @list = [3, 1, 2] +Output: 6 +1 x 2 x 3 = 6 +---------------------- +Input: @list = [4, 1, 3, 2] +Output: 24 +2 x 3 x 4 = 24 +---------------------- +Input: @list = [-1, 0, 1, 3, 1] +Output: 3 +1 x 1 x 3 = 3 +---------------------- +Input: @list = [-8, 2, -9, 0, -4, 3] +Output: 216 +-9 x -8 x 3 = 216 +----------------------------------------- +=# + + diff --git a/challenge-218/robert-dicicco/perl/ch-1.pl b/challenge-218/robert-dicicco/perl/ch-1.pl new file mode 100644 index 0000000000..9517f308ba --- /dev/null +++ b/challenge-218/robert-dicicco/perl/ch-1.pl @@ -0,0 +1,59 @@ +#!/usr/bin/env perl +=begin comment +----------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-05-22 +Challenge 218 Maximum Product ( Perl ) +----------------------------------------- +=cut +use strict; +use warnings; +use feature 'say'; +use Algorithm::Combinatorics qw(permutations combinations); + +my @lists = ([3, 1, 2],[4, 1, 3, 2],[-1, 0, 1, 3, 1],[-8, 2, -9, 0, -4, 3]); + +my $maxval = 0; + +my $threelist = 0; + +for my $lst (@lists) { + say "Input: \@list = [@$lst]"; + my $iter = combinations($lst, 3); + while (my $c = $iter->next) { + my $threeval = @{$c}[0] * @{$c}[1] * @{$c}[2]; + if ($threeval > $maxval) { + $maxval = $threeval; + $threelist = $c; + } + } + say "Output: $maxval"; + my @sorted = sort(@{$threelist}); + say "$sorted[0] x $sorted[1] x $sorted[2] = ",$maxval; + $maxval = 0; + $threelist = 0; + say ""; +} + +=begin comment +----------------------------------------- +SAMPLE OUTPUT +perl .\MaxProduct.pl + +Input: @list = [3 1 2] +Output: 6 +1 x 2 x 3 = 6 + +Input: @list = [4 1 3 2] +Output: 24 +2 x 3 x 4 = 24 + +Input: @list = [-1 0 1 3 1] +Output: 3 +1 x 1 x 3 = 3 + +Input: @list = [-8 2 -9 0 -4 3] +Output: 216 +-8 x -9 x 3 = 216 +----------------------------------------- +=cut diff --git a/challenge-218/robert-dicicco/python/ch-1.py b/challenge-218/robert-dicicco/python/ch-1.py new file mode 100644 index 0000000000..0cb5363087 --- /dev/null +++ b/challenge-218/robert-dicicco/python/ch-1.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python + +# ----------------------------------------- +# AUTHOR: Robert DiCicco +# DATE : 2023-05-22 +# Challenge 218 Maximum Product ( Python ) +# ----------------------------------------- + +from itertools import combinations + + +lists = [[3, 1, 2],[4, 1, 3, 2],[-1, 0, 1, 3, 1],[-8, 2, -9, 0, -4, 3]] + +maxthree = [] + +for lst in lists: + print("Input: @list = ",lst) + maxval = 0 + maxthree = [] + for combo in list(combinations(lst,3)): + prod = combo[0] * combo[1] * combo[2] + if prod > maxval: + maxval = prod + maxthree = combo + print("Output: ",maxval) + maxthree = sorted(maxthree) + print(maxthree[0]," x ", maxthree[1], " x ", maxthree[2], " = ",maxval,"\n") + maxval = 0 + +# ----------------------------------------- +# SAMPLE OUTPUT +# python .\MaxProduct.py + +# Input: @list = [3, 1, 2] +# Output: 6 +# 1 x 2 x 3 = 6 + +# Input: @list = [4, 1, 3, 2] +# Output: 24 +# 2 x 3 x 4 = 24 + +# Input: @list = [-1, 0, 1, 3, 1] +# Output: 3 +# 1 x 1 x 3 = 3 + +# Input: @list = [-8, 2, -9, 0, -4, 3] +# Output: 216 +# -9 x -8 x 3 = 216 +# ----------------------------------------- + + diff --git a/challenge-218/robert-dicicco/raku/ch-1.raku b/challenge-218/robert-dicicco/raku/ch-1.raku new file mode 100644 index 0000000000..76b980059a --- /dev/null +++ b/challenge-218/robert-dicicco/raku/ch-1.raku @@ -0,0 +1,57 @@ +#!/usr/bin/en raku +=begin comment +----------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-05-22 +Challenge 218 Maximum Product ( Raku ) +----------------------------------------- +=end comment + +my @lists = ([3, 1, 2],[4, 1, 3, 2],[-1, 0, 1, 3, 1],[-8, 2, -9, 0, -4, 3]); + +my $maxval = 0; + +my $threelist = 0; +my @threelist = (); + +for (@lists) -> @lst { + for @lst.combinations(3) -> @combo { + my $threeval = [*] @combo; + if $threeval > $maxval { + $maxval = $threeval; + @threelist = @combo; + } + } + say "Input: \@list = ",@lst; + say "Output: ",$maxval; + @threelist = @threelist.sort; + say @threelist[0], " x ", @threelist.[1], " x ", @threelist[2], " = $maxval"; + @threelist = (); + $maxval = 0; + say ""; +} + +=begin comment +----------------------------------------- +SAMPLE OUTPUT + +raku .\MaxProduct.rk +Input: @list = [3 1 2] +Output: 6 +1 x 2 x 3 = 6 + +Input: @list = [4 1 3 2] +Output: 24 +2 x 3 x 4 = 24 + +Input: @list = [-1 0 1 3 1] +Output: 3 +1 x 1 x 3 = 3 + +Input: @list = [-8 2 -9 0 -4 3] +Output: 216 +-9 x -8 x 3 = 216 +----------------------------------------- +=end comment + + diff --git a/challenge-218/robert-dicicco/ruby/ch-1.rb b/challenge-218/robert-dicicco/ruby/ch-1.rb new file mode 100644 index 0000000000..5bf33e2359 --- /dev/null +++ b/challenge-218/robert-dicicco/ruby/ch-1.rb @@ -0,0 +1,56 @@ +#!/usr/bin/env ruby +=begin +----------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-05-22 +Challenge 218 Maximum Product ( Ruby ) +----------------------------------------- +=end + +lists = [[3, 1, 2],[4, 1, 3, 2],[-1, 0, 1, 3, 1],[-8, 2, -9, 0, -4, 3]] + +maxval = 0 +maxthree = [] + +lists.each do |lst| +puts("Input: @list = #{lst}") + ax = lst.combination(3).to_a.sort + ax.each do |c| + prod = c[0] * c[1] * c[2] + if prod > maxval + maxval = prod + maxthree = c.sort + end + end + puts("Output: #{maxval}") + puts("#{maxthree[0]} x #{maxthree[1]} x #{maxthree[2]} = #{maxval}") + maxval = 0 + maxthree = [] + puts("") +end + +=begin +----------------------------------------- +SAMPLE OUTPUT +ruby .\MaxProduct.rb + +Input: @list = [3, 1, 2] +Output: 6 +1 x 2 x 3 = 6 + +Input: @list = [4, 1, 3, 2] +Output: 24 +2 x 3 x 4 = 24 + +Input: @list = [-1, 0, 1, 3, 1] +Output: 3 +1 x 1 x 3 = 3 + +Input: @list = [-8, 2, -9, 0, -4, 3] +Output: 216 +-9 x -8 x 3 = 216 +----------------------------------------- +=end + + + diff --git a/challenge-218/steven-wilson/perl/ch-01.pl b/challenge-218/steven-wilson/perl/ch-1.pl index 29fccf244d..29fccf244d 100644 --- a/challenge-218/steven-wilson/perl/ch-01.pl +++ b/challenge-218/steven-wilson/perl/ch-1.pl diff --git a/challenge-218/ziameraj16/java/MaximumProduct.java b/challenge-218/ziameraj16/java/MaximumProduct.java new file mode 100644 index 0000000000..66c8277c82 --- /dev/null +++ b/challenge-218/ziameraj16/java/MaximumProduct.java @@ -0,0 +1,26 @@ +import java.util.*; + +public class MaximumProduct { + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + List<Integer> values = Arrays.stream(scanner.nextLine().split(",")).map(Integer::valueOf).toList(); + int maxProduct = 0; + String str = null; + int size = values.size(); + for (int x = 0; x < size - 2; x++) { + for (int y = x + 1; y < size - 1; y++) { + for (int z = y + 1; z < size; z++) { + Integer first = values.get(x); + Integer second = values.get(y); + Integer third = values.get(z); + if (first * second * third > maxProduct) { + maxProduct = first * second * third; + str = String.format("%s x %s x %s => %s", first, second, third, maxProduct); + } + } + } + } + System.out.println(str); + } +} diff --git a/members.json b/members.json index 1b2bf6dfa2..4f6c172369 100644 --- a/members.json +++ b/members.json @@ -14,7 +14,7 @@ "alexander-karelas" : "Alexander Karelas", "alexander-pankoff" : "Alexander Pankoff", "andinus" : "Andinus", - "aut0exec" : "Aut0exec", + "aut0exec" : "Rob Turner", "avery-adams" : "Avery Adams", "mathmauney" : "Alex Mauney", "alicia-bielsa" : "Alicia Bielsa", diff --git a/stats/pwc-challenge-072.json b/stats/pwc-challenge-072.json index 7a8050f607..db5e94bc52 100644 --- a/stats/pwc-challenge-072.json +++ b/stats/pwc-challenge-072.json @@ -1,228 +1,11 @@ { - "plotOptions" : { - "series" : { - "dataLabels" : { - "enabled" : 1, - "format" : "{point.y}" - }, - "borderWidth" : 0 - } - }, - "title" : { - "text" : "The Weekly Challenge - 072" - }, - "xAxis" : { - "type" : "category" - }, - "subtitle" : { - "text" : "[Champions: 39] Last updated at 2022-04-20 12:40:31 GMT" + "chart" : { + "type" : "column" }, - "series" : [ - { - "data" : [ - { - "name" : "Adam Russell", - "drilldown" : "Adam Russell", - "y" : 4 - }, - { - "name" : "Andrew Shitov", - "y" : 4, - "drilldown" : "Andrew Shitov" - }, - { - "name" : "Arne Sommer", - "y" : 5, - "drilldown" : "Arne Sommer" - }, - { - "name" : "Athanasius", - "y" : 4, - "drilldown" : "Athanasius" - }, - { - "name" : "Ben Davies", - "y" : 2, - "drilldown" : "Ben Davies" - }, - { - "drilldown" : "Bob Lied", - "y" : 2, - "name" : "Bob Lied" - }, - { - "y" : 2, - "drilldown" : "Cheok-Yin Fung", - "name" : "Cheok-Yin Fung" - }, - { - "name" : "Colin Crain", - "y" : 5, - "drilldown" : "Colin Crain" - }, - { - "name" : "Cristina Heredia", - "drilldown" : "Cristina Heredia", - "y" : 2 - }, - { - "name" : "Dave Jacoby", - "y" : 3, - "drilldown" : "Dave Jacoby" - }, - { - "name" : "Duncan C. White", - "y" : 2, - "drilldown" : "Duncan C. White" - }, - { - "drilldown" : "E. Choroba", - "y" : 2, - "name" : "E. Choroba" - }, - { - "drilldown" : "Feng Chang", - "y" : 1, - "name" : "Feng Chang" - }, - { - "y" : 5, - "drilldown" : "Jaldhar H. Vyas", - "name" : "Jaldhar H. Vyas" - }, - { - "name" : "Jan Krnavek", - "y" : 2, - "drilldown" : "Jan Krnavek" - }, - { - "y" : 2, - "drilldown" : "Jason Messer", - "name" : "Jason Messer" - }, - { - "name" : "Javier Luque", - "drilldown" : "Javier Luque", - "y" : 5 - }, - { - "name" : "Jorg Sommrey", - "drilldown" : "Jorg Sommrey", - "y" : 2 - }, - { - "name" : "Lance Wicks", - "y" : 2, - "drilldown" : "Lance Wicks" - }, - { - "y" : 5, - "drilldown" : "Laurent Rosenfeld", - "name" : "Laurent Rosenfeld" - }, - { - "name" : "Luca Ferrari", - "drilldown" : "Luca Ferrari", - "y" : 4 - }, - { - "y" : 2, - "drilldown" : "Mark Anderson", - "name" : "Mark Anderson" - }, - { - "y" : 2, - "drilldown" : "Markus Holzer", - "name" : "Markus Holzer" - }, - { - "name" : "Mohammad S Anwar", - "drilldown" : "Mohammad S Anwar", - "y" : 5 - }, - { - "name" : "Myoungjin Jeon", - "y" : 4, - "drilldown" : "Myoungjin Jeon" - }, - { - "name" : "Niels van Dijke", - "drilldown" : "Niels van Dijke", - "y" : 2 - }, - { - "drilldown" : "Noud Aldenhoven", - "y" : 2, - "name" : "Noud Aldenhoven" - }, - { - "name" : "Paulo Custodio", - "drilldown" : "Paulo Custodio", - "y" : 2 - }, - { - "y" : 2, - "drilldown" : "Pete Houston", - "name" : "Pete Houston" - }, - { - "name" : "Roger Bell_West", - "y" : 5, - "drilldown" : "Roger Bell_West" - }, - { - "y" : 3, - "drilldown" : "Simon Green", - "name" : "Simon Green" - }, - { - "name" : "Simon Miner", - "drilldown" : "Simon Miner", - "y" : 2 - }, - { - "drilldown" : "Simon Proctor", - "y" : 4, - "name" : "Simon Proctor" - }, - { - "y" : 2, - "drilldown" : "Stuart Little", - "name" : "Stuart Little" - }, - { - "y" : 4, - "drilldown" : "Ulrich Rieke", - "name" : "Ulrich Rieke" - }, - { - "name" : "Walt Mankowski", - "y" : 3, - "drilldown" : "Walt Mankowski" - }, - { - "name" : "Wanderdoc", - "drilldown" : "Wanderdoc", - "y" : 2 - }, - { - "name" : "William West", - "y" : 1, - "drilldown" : "William West" - }, - { - "name" : "Yary Hluchan", - "drilldown" : "Yary Hluchan", - "y" : 2 - } - ], - "colorByPoint" : 1, - "name" : "The Weekly Challenge - 072" - } - ], "drilldown" : { "series" : [ { + "name" : "Adam Russell", "data" : [ [ "Perl", @@ -233,8 +16,7 @@ 2 ] ], - "id" : "Adam Russell", - "name" : "Adam Russell" + "id" : "Adam Russell" }, { "data" : [ @@ -247,11 +29,11 @@ 2 ] ], - "id" : "Andrew Shitov", - "name" : "Andrew Shitov" + "name" : "Andrew Shitov", + "id" : "Andrew Shitov" }, { - "id" : "Arne Sommer", + "name" : "Arne Sommer", "data" : [ [ "Perl", @@ -266,7 +48,7 @@ 1 ] ], - "name" : "Arne Sommer" + "id" : "Arne Sommer" }, { "data" : [ @@ -279,41 +61,40 @@ 2 ] ], - "id" : "Athanasius", - "name" : "Athanasius" + "name" : "Athanasius", + "id" : "Athanasius" }, { + "id" : "Ben Davies", "data" : [ [ "Raku", 2 ] ], - "id" : "Ben Davies", "name" : "Ben Davies" }, { - "id" : "Bob Lied", + "name" : "Bob Lied", "data" : [ [ "Perl", 2 ] ], - "name" : "Bob Lied" + "id" : "Bob Lied" }, { - "name" : "Cheok-Yin Fung", "id" : "Cheok-Yin Fung", "data" : [ [ "Perl", 2 ] - ] + ], + "name" : "Cheok-Yin Fung" }, { - "id" : "Colin Crain", "data" : [ [ "Perl", @@ -328,19 +109,22 @@ 1 ] ], - "name" : "Colin Crain" + "name" : "Colin Crain", + "id" : "Colin Crain" }, { - "id" : "Cristina Heredia", + "name" : "Cristina Heredia", "data" : [ [ "Perl", 2 ] ], - "name" : "Cristina Heredia" + "id" : "Cristina Heredia" }, { + "id" : "Dave Jacoby", + "name" : "Dave Jacoby", "data" : [ [ "Perl", @@ -350,29 +134,27 @@ "Blog", 1 ] - ], - "id" : "Dave Jacoby", - "name" : "Dave Jacoby" + ] }, { "id" : "Duncan C. White", + "name" : "Duncan C. White", "data" : [ [ "Perl", 2 ] - ], - "name" : "Duncan C. White" + ] }, { - "name" : "E. Choroba", - "id" : "E. Choroba", "data" : [ [ "Perl", 2 ] - ] + ], + "name" : "E. Choroba", + "id" : "E. Choroba" }, { "data" : [ @@ -381,11 +163,12 @@ 1 ] ], - "id" : "Feng Chang", - "name" : "Feng Chang" + "name" : "Feng Chang", + "id" : "Feng Chang" }, { "id" : "Jaldhar H. Vyas", + "name" : "Jaldhar H. Vyas", "data" : [ [ "Perl", @@ -399,8 +182,7 @@ "Blog", 1 ] - ], - "name" : "Jaldhar H. Vyas" + ] }, { "id" : "Jan Krnavek", @@ -413,18 +195,17 @@ "name" : "Jan Krnavek" }, { - "name" : "Jason Messer", + "id" : "Jason Messer", "data" : [ [ "Raku", 2 ] ], - "id" : "Jason Messer" + "name" : "Jason Messer" }, { "name" : "Javier Luque", - "id" : "Javier Luque", "data" : [ [ "Perl", @@ -438,17 +219,18 @@ "Blog", 1 ] - ] + ], + "id" : "Javier Luque" }, { - "id" : "Jorg Sommrey", + "name" : "Jorg Sommrey", "data" : [ [ "Perl", 2 ] ], - "name" : "Jorg Sommrey" + "id" : "Jorg Sommrey" }, { "id" : "Lance Wicks", @@ -465,6 +247,7 @@ "name" : "Lance Wicks" }, { + "id" : "Laurent Rosenfeld", "data" : [ [ "Perl", @@ -479,11 +262,20 @@ 1 ] ], - "id" : "Laurent Rosenfeld", "name" : "Laurent Rosenfeld" }, { - "name" : "Luca Ferrari", + "id" : "Lubos Kolouch", + "name" : "Lubos Kolouch", + "data" : [ + [ + "Perl", + 2 + ] + ] + }, + { + "id" : "Luca Ferrari", "data" : [ [ "Raku", @@ -494,17 +286,17 @@ 2 ] ], - "id" : "Luca Ferrari" + "name" : "Luca Ferrari" }, { - "id" : "Mark Anderson", + "name" : "Mark Anderson", "data" : [ [ "Raku", 2 ] ], - "name" : "Mark Anderson" + "id" : "Mark Anderson" }, { "id" : "Markus Holzer", @@ -517,7 +309,6 @@ "name" : "Markus Holzer" }, { - "name" : "Mohammad S Anwar", "data" : [ [ "Perl", @@ -532,9 +323,11 @@ 1 ] ], + "name" : "Mohammad S Anwar", "id" : "Mohammad S Anwar" }, { + "id" : "Myoungjin Jeon", "data" : [ [ "Perl", @@ -545,51 +338,49 @@ 2 ] ], - "id" : "Myoungjin Jeon", "name" : "Myoungjin Jeon" }, { |
