diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-08-07 01:17:31 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-08-07 01:17:31 +0100 |
| commit | c9d51119672fa4703f855351b279156143231606 (patch) | |
| tree | 39df6d1d97742374245ae735a3fdaa8719379265 | |
| parent | 6194a90afd366a49841cbc01365dcbacefd9bb00 (diff) | |
| download | perlweeklychallenge-club-c9d51119672fa4703f855351b279156143231606.tar.gz perlweeklychallenge-club-c9d51119672fa4703f855351b279156143231606.tar.bz2 perlweeklychallenge-club-c9d51119672fa4703f855351b279156143231606.zip | |
- Added solutions by Laurent Rosenfeld.
22 files changed, 1428 insertions, 1208 deletions
diff --git a/challenge-124/laurent-rosenfeld/awk/ch-1.awk b/challenge-124/laurent-rosenfeld/awk/ch-1.awk new file mode 100644 index 0000000000..4b7c7b3884 --- /dev/null +++ b/challenge-124/laurent-rosenfeld/awk/ch-1.awk @@ -0,0 +1,37 @@ +echo ' +llll11111llll +lll1lllll1lll +ll1lllllll1ll +l1lllllllll1l +l1lllllllll1l +l1lllllllll1l +l1lllllllll1l +l1lllllllll1l +ll1lllllll1ll +lll1lllll1lll +llll11111llll +llllll1llllll +llllll1llllll +llllll1llllll +llll11111llll +llllll1llllll +llllll1llllll +' | awk 'gsub("l", " ") gsub("1", "*")' + + ***** + * * + * * + * * + * * + * * + * * + * * + * * + * * + ***** + * + * + * + ***** + * + * diff --git a/challenge-124/laurent-rosenfeld/blog.txt b/challenge-124/laurent-rosenfeld/blog.txt new file mode 100644 index 0000000000..dd6230a7d1 --- /dev/null +++ b/challenge-124/laurent-rosenfeld/blog.txt @@ -0,0 +1 @@ +http://blogs.perl.org/users/laurent_r/2021/08/perl-weekly-challenge-124-happy-women-day-and-tug-of-war.html diff --git a/challenge-124/laurent-rosenfeld/perl/ch-1.pl b/challenge-124/laurent-rosenfeld/perl/ch-1.pl new file mode 100644 index 0000000000..dd7aa2c14c --- /dev/null +++ b/challenge-124/laurent-rosenfeld/perl/ch-1.pl @@ -0,0 +1,14 @@ +use strict; +use warnings; +use feature "say"; + +my $bar = " ^^^^^"; +my @pairs = (" ^ ^", " ^ ^", "^ ^"); +my $single = " ^"; + +say $bar; +say join "\n", @pairs[0, 1, 2, 2, 2, 2, 2, 1, 0]; +say $bar; +say $single for 1..3; +say $bar; +say $single for 1..2; diff --git a/challenge-124/laurent-rosenfeld/perl/ch-2.pl b/challenge-124/laurent-rosenfeld/perl/ch-2.pl new file mode 100644 index 0000000000..cdf7dc7be1 --- /dev/null +++ b/challenge-124/laurent-rosenfeld/perl/ch-2.pl @@ -0,0 +1,49 @@ +use strict; +use warnings; +use feature "say"; + +my @comb; + +sub combine { + my $count = shift; + my @out = @{$_[0]}; + my @in = @{$_[1]}; + if ($count == 0) { + push @comb, [@out]; + return; + } + for my $i (0..$#in) { + combine ($count - 1, [@out, $in[$i]], [@in[0..$i -1], @in[$i+1..$#in]]); + } +} + +sub sum { + my $sum = 0; + $sum += $_ for @_; + return $sum; +} + +sub find_smallest_diff { + my @in = @{$_[0]}; + my $min_val; + my $min_seq; + for my $c (@comb) { + my @c1 = @$c; + my %seen = map { $_ => 1 } @c1; + my @c2 = grep { not exists $seen{$_}} @in; + my $diff = abs(sum(@c2) - sum(@c1)); + $min_val = $diff unless defined $min_val; + if ($diff < $min_val) { + $min_val = $diff; + $min_seq = ("@c1 -- @c2 "); + } + } + return "$min_seq => $min_val"; +} + +for my $test ( [10, 20, 30, 40, 50, 60, 70, 80, 90, 100], + [10, -15, 20, 30, -25, 0, 5, 40, -5] ) { + my $count = int (@$test / 2); + combine $count, [], $test; + say find_smallest_diff $test; +} diff --git a/challenge-124/laurent-rosenfeld/python/ch-1.py b/challenge-124/laurent-rosenfeld/python/ch-1.py new file mode 100644 index 0000000000..602ef9d549 --- /dev/null +++ b/challenge-124/laurent-rosenfeld/python/ch-1.py @@ -0,0 +1,3 @@ +lines = (" ^^^^^", " ^ ^", " ^ ^", "^ ^", " ^") +for x in 0, 1, 2, 3, 3, 3, 3, 3, 3, 2, 1, 0, 4, 4, 4, 0, 4, 4: + print(lines[x]) diff --git a/challenge-124/laurent-rosenfeld/raku/ch-1.raku b/challenge-124/laurent-rosenfeld/raku/ch-1.raku new file mode 100644 index 0000000000..2ad9b55743 --- /dev/null +++ b/challenge-124/laurent-rosenfeld/raku/ch-1.raku @@ -0,0 +1,12 @@ +use v6; + +my $bar = " ^^^^^"; +my @pairs = " ^ ^", " ^ ^", "^ ^"; +my $single = " ^"; + +say $bar; +say join "\n", @pairs[0, 1, 2, 2, 2, 2, 2, 1, 0]; +say $bar; +say $single for 1..3; +say $bar; +say $single for 1..2; diff --git a/challenge-124/laurent-rosenfeld/raku/ch-2.raku b/challenge-124/laurent-rosenfeld/raku/ch-2.raku new file mode 100644 index 0000000000..6a13cb1fac --- /dev/null +++ b/challenge-124/laurent-rosenfeld/raku/ch-2.raku @@ -0,0 +1,20 @@ +use v6; + +sub find_smallest_diff(@in) { + my $inbag = @in.Bag; + my $min_val = Inf; + my $min_seq; + my $count = @in.elems div 2; + for @in.combinations: $count -> @c1 { + my @c2 = ($inbag (-) @c1.Bag).keys; + if abs(@c2.sum - @c1.sum) < $min_val { + $min_val = abs(@c2.sum - @c1.sum); + $min_seq = (@c1, " -- ", @c2); + } + } + return "$min_seq => $min_val"; +} + +my @tests = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100], + [10, -15, 20, 30, -25, 0, 5, 40, -5]; +say find_smallest_diff($_) for @tests; diff --git a/challenge-124/laurent-rosenfeld/scala/ch-1.scala b/challenge-124/laurent-rosenfeld/scala/ch-1.scala new file mode 100644 index 0000000000..f6704e51a4 --- /dev/null +++ b/challenge-124/laurent-rosenfeld/scala/ch-1.scala @@ -0,0 +1,24 @@ +object root extends App { + var venus = """ +OOOO00000OOOO +OOO0OOOOO0OOO +OO0OOOOOOO0OO +O0OOOOOOOOO0O +O0OOOOOOOOO0O +O0OOOOOOOOO0O +O0OOOOOOOOO0O +O0OOOOOOOOO0O +OO0OOOOOOO0OO +OOO0OOOOO0OOO +OOOO00000OOOO +OOOOOO0OOOOOO +OOOOOO0OOOOOO +OOOOOO0OOOOOO +OOOO00000OOOO +OOOOOO0OOOOOO +OOOOOO0OOOOOO""" + val pattern = "O".r + venus = pattern replaceAllIn (venus, " ") + val pattern2 = "0".r + println(pattern2 replaceAllIn (venus, "+")) +} diff --git a/challenge-124/laurent-rosenfeld/sed/ch-1.sed b/challenge-124/laurent-rosenfeld/sed/ch-1.sed new file mode 100644 index 0000000000..f44ca2d39e --- /dev/null +++ b/challenge-124/laurent-rosenfeld/sed/ch-1.sed @@ -0,0 +1,37 @@ +echo ' +llll11111llll +lll1lllll1lll +ll1lllllll1ll +l1lllllllll1l +l1lllllllll1l +l1lllllllll1l +l1lllllllll1l +l1lllllllll1l +ll1lllllll1ll +lll1lllll1lll +llll11111llll +llllll1llllll +llllll1llllll +llllll1llllll +llll11111llll +llllll1llllll +llllll1llllll +' | sed 's/l/ /g; s/1/x/g' + + xxxxx + x x + x x + x x + x x + x x + x x + x x + x x + x x + xxxxx + x + x + x + xxxxx + x + x diff --git a/stats/pwc-current.json b/stats/pwc-current.json index 9003ebfc32..62ffc51024 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,134 +1,30 @@ { - "subtitle" : { - "text" : "[Champions: 18] Last updated at 2021-08-07 00:05:31 GMT" - }, - "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/>" + "chart" : { + "type" : "column" }, "legend" : { "enabled" : 0 }, - "series" : [ - { - "data" : [ - { - "name" : "Bruce Gray", - "y" : 4, - "drilldown" : "Bruce Gray" - }, - { - "name" : "Cheok-Yin Fung", - "drilldown" : "Cheok-Yin Fung", - "y" : 1 - }, - { - "name" : "Dave Jacoby", - "drilldown" : "Dave Jacoby", - "y" : 3 - }, - { - "name" : "E. Choroba", - "drilldown" : "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" - }, - { - "name" : "kjetillll", - "y" : 2, - "drilldown" : "kjetillll" - }, - { - "y" : 4, - "drilldown" : "Luca Ferrari", - "name" : "Luca Ferrari" - }, - { - "y" : 1, - "drilldown" : "Mark Anderson", - "name" : "Mark Anderson" - }, - { - "y" : 2, - "drilldown" : "Niels van Dijke", - "name" : "Niels van Dijke" - }, - { - "name" : "Peter Campbell Smith", - "drilldown" : "Peter Campbell Smith", - "y" : 1 - }, - { - "drilldown" : "Roger Bell_West", - "y" : 5, - "name" : "Roger Bell_West" - }, - { - "y" : 2, - "drilldown" : "Simon Green", - "name" : "Simon Green" - }, - { - "y" : 2, - "drilldown" : "Simon Proctor", - "name" : "Simon Proctor" - }, - { - "drilldown" : "Stuart Little", - "y" : 4, - "name" : "Stuart Little" - }, - { - "y" : 3, - "drilldown" : "Ulrich Rieke", - "name" : "Ulrich Rieke" - }, - { - "drilldown" : "W. Luis Mochan", - "y" : 3, - "name" : "W. Luis Mochan" - } - ], - "colorByPoint" : 1, - "name" : "The Weekly Challenge - 124" - } - ], - "title" : { - "text" : "The Weekly Challenge - 124" - }, "xAxis" : { "type" : "category" }, - "chart" : { - "type" : "column" + "tooltip" : { + "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/>", + "followPointer" : 1 + }, + "subtitle" : { + "text" : "[Champions: 19] Last updated at 2021-08-07 00:17:15 GMT" + }, + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } }, "drilldown" : { "series" : [ { + "name" : "Bruce Gray", "id" : "Bruce Gray", "data" : [ [ @@ -139,18 +35,17 @@ "Raku", 2 ] - ], - "name" : "Bruce Gray" + ] }, { "name" : "Cheok-Yin Fung", - "id" : "Cheok-Yin Fung", "data" : [ [ "Perl", 1 ] - ] + ], + "id" : "Cheok-Yin Fung" }, { "name" : "Dave Jacoby", @@ -167,17 +62,17 @@ ] }, { - "id" : "E. Choroba", "data" : [ [ "Perl", 2 ] ], + "id" : "E. Choroba", "name" : "E. Choroba" }, { - "id" : "Flavio Poletti", + "name" : "Flavio Poletti", "data" : [ [ "Perl", @@ -192,11 +87,9 @@ 2 ] ], - "name" : "Flavio Poletti" + "id" : "Flavio Poletti" }, { - "name" : "James Smith", - "id" : "James Smith", "data" : [ [ "Perl", @@ -206,7 +99,9 @@ "Blog", 1 ] - ] + ], + "id" : "James Smith", + "name" : "James Smith" }, { "name" : "Jorg Sommrey", @@ -220,16 +115,34 @@ }, { "name" : "kjetillll", + "id" : "kjetillll", + "data" : [ + [ + "Perl", + 2 + ] + ] + }, + { + "id" : "Laurent Rosenfeld", "data" : [ [ "Perl", 2 + ], + [ + "Raku", + 2 + ], + [ + "Blog", + 1 ] ], - "id" : "kjetillll" + "name" : "Laurent Rosenfeld" }, { - "name" : "Luca Ferrari", + "id" : "Luca Ferrari", "data" : [ [ "Raku", @@ -240,40 +153,39 @@ 2 ] ], - "id" : "Luca Ferrari" + "name" : "Luca Ferrari" }, { "name" : "Mark Anderson", + "id" : "Mark Anderson", "data" : [ [ "Raku", 1 ] - ], - "id" : "Mark Anderson" + ] }, { + "id" : "Niels van Dijke", "data" : [ [ "Perl", 2 ] ], - "id" : "Niels van Dijke", "name" : "Niels van Dijke" }, { - "id" : "Peter Campbell Smith", "data" : [ [ "Perl", 1 ] ], + "id" : "Peter Campbell Smith", "name" : "Peter Campbell Smith" }, { - "name" : "Roger Bell_West", "id" : "Roger Bell_West", "data" : [ [ @@ -288,9 +200,11 @@ "Blog", 1 ] - ] + ], + "name" : "Roger Bell_West" }, { + "name" : "Simon Green", "id" : "Simon Green", "data" : [ [ @@ -301,8 +215,7 @@ "Blog", 1 ] - ], - "name" : "Simon Green" + ] }, { "name" : "Simon Proctor", @@ -315,6 +228,8 @@ "id" : "Simon Proctor" }, { + "name" : "Stuart Little", + "id" : "Stuart Little", "data" : [ [ "Perl", @@ -324,12 +239,10 @@ "Raku", 2 ] - ], - "id" : "Stuart Little", - "name" : "Stuart Little" + ] }, { - "id" : "Ulrich Rieke", + "name" : "Ulrich Rieke", "data" : [ [ "Perl", @@ -340,10 +253,9 @@ 1 ] ], - "name" : "Ulrich Rieke" + "id" : "Ulrich Rieke" }, { - "name" : "W. Luis Mochan", "data" : [ [ "Perl", @@ -354,13 +266,124 @@ 1 ] ], - "id" : "W. Luis Mochan" + "id" : "W. Luis Mochan", + "name" : "W. Luis Mochan" } ] }, - "yAxis" : { - "title" : { - "text" : "Total Solutions" + "plotOptions" : { + "series" : { + "borderWidth" : 0, + "dataLabels" : { + "enabled" : 1, + "format" : "{point.y}" + } + } + }, + "title" : { + "text" : "The Weekly Challenge - 124" + }, + "series" : [ + { + "data" : [ + { + "drilldown" : "Bruce Gray", + "y" : 4, + "name" : "Bruce Gray" + }, + { + "name" : "Cheok-Yin Fung", + "y" : 1, + "drilldown" : "Cheok-Yin Fung" + }, + { + "y" : 3, + "drilldown" : "Dave Jacoby", + "name" : "Dave Jacoby" + }, + { + "name" : "E. Choroba", + "y" : 2, + "drilldown" : "E. Choroba" + }, + { + "y" : 6, + "drilldown" : "Flavio Poletti", + "name" : "Flavio Poletti" + }, + { + "name" : "James Smith", + "drilldown" : "James Smith", + "y" : 3 + }, + { + "drilldown" : "Jorg Sommrey", + "y" : 2, + "name" : "Jorg Sommrey" + }, + { + "y" : 2, + "drilldown" : "kjetillll", + "name" : "kjetillll" + }, + { + "drilldown" : "Laurent Rosenfeld", + "y" : 5, + "name" : "Laurent Rosenfeld" + }, + { + "drilldown" : "Luca Ferrari", + "y" : 4, + "name" : "Luca Ferrari" + }, + { + "name" : "Mark Anderson", + "drilldown" : "Mark Anderson", + "y" : 1 + }, + { + "name" : "Niels van Dijke", + "drilldown" : "Niels van Dijke", + "y" : 2 + }, + { + "y" : 1, + "drilldown" : "Peter Campbell Smith", + "name" : "Peter Campbell Smith" + }, + { + "name" : "Roger Bell_West", + "y" : 5, + "drilldown" : "Roger Bell_West" + }, + { + "drilldown" : "Simon Green", + "y" : 2, + "name" : "Simon Green" + }, + { + "y" : 2, + "drilldown" : "Simon Proctor", + "name" : "Simon Proctor" + }, + { + "name" : "Stuart Little", + "y" : 4, + "drilldown" : "Stuart Little" + }, + { + "name" : "Ulrich Rieke", + "y" : 3, + "drilldown" : "Ulrich Rieke" + }, + { + "name" : "W. Luis Mochan", + "y" : 3, + "drilldown" : "W. Luis Mochan" + } + ], + "name" : "The Weekly Challenge - 124", + "colorByPoint" : 1 } - } + ] } diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index 5c755f77a4..a2173d8dd0 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -1,56 +1,50 @@ { - "tooltip" : { - "pointFormat" : "<b>{point.y:.0f}</b>" - }, - "subtitle" : { - "text" : "Last updated at 2021-08-07 00:05:31 GMT" - }, - "chart" : { - "type" : "column" - }, - "yAxis" : { - "min" : 0, - "title" : { - "text" : null - } - }, - "legend" : { - "enabled" : "false" - }, "series" : [ { - "name" : "Contributions", "data" : [ [ "Blog", - 1784 + 1785 ], [ "Perl", - 5939 + 5941 ], [ "Raku", - 3699 + 3701 ] ], "dataLabels" : { - "rotation" : -90, - "color" : "#FFFFFF", + "enabled" : "true", + "align" : "right", + "format" : "{point.y:.0f}", "y" : 10, "style" : { "fontSize" : "13px", "fontFamily" : "Verdana, sans-serif" }, - "enabled" : "true", - "format" : "{point.y:.0f}", - "align" : "right" - } + "color" : "#FFFFFF", + "rotation" : -90 + }, + "name" : "Contributions" } ], "title" : { "text" : "The Weekly Challenge Contributions [2019 - 2021]" }, + "subtitle" : { + "text" : "Last updated at 2021-08-07 00:17:14 GMT" + }, + "yAxis" : { + "min" : 0, + "title" : { + "text" : null + } + }, + "tooltip" : { + "pointFormat" : "<b>{point.y:.0f}</b>" + }, "xAxis" : { "type" : "category", "labels" : { @@ -59,5 +53,11 @@ "fontSize" : "13px" } } + }, + "chart" : { + "type" : "column" + }, + "legend" : { + "enabled" : "false" } } diff --git a/stats/pwc-language-breakdown.json b/stats/pwc-language-breakdown.json index 29472f5b51..c59434bcc1 100644 --- a/stats/pwc-language-breakdown.json +++ b/stats/pwc-language-breakdown.json @@ -1,7 +1,11 @@ { - "yAxis" : { - "title" : { - "text" : "Total Solutions" + "plotOptions" : { + "series" : { + "dataLabels" : { + "enabled" : 1, + "format" : "{point.y}" + }, + "borderWidth" : 0 } }, "drilldown" : { @@ -26,6 +30,7 @@ }, { "name" : "002", + "id" : "002", "data" : [ [ "Perl", @@ -39,12 +44,10 @@ "Blog", 10 ] - ], - "id" : "002" + ] }, { "name" : "003", - "id" : "003", "data" : [ [ "Perl", @@ -58,9 +61,11 @@ "Blog", 9 ] - ] + ], + "id" : "003" }, { + "name" : "004", "data" : [ [ "Perl", @@ -75,10 +80,10 @@ 10 ] ], - "id" : "004", - "name" : "004" + "id" : "004" }, { + "name" : "005", "id" : "005", "data" : [ [ @@ -93,11 +98,11 @@ "Blog", 12 ] - ], - "name" : "005" + ] }, { "name" : "006", + "id" : "006", "data" : [ [ "Perl", @@ -111,8 +116,7 @@ "Blog", 7 ] - ], - "id" : "006" + ] }, { "id" : "007", @@ -169,6 +173,7 @@ "name" : "009" }, { + "id" : "010", "data" : [ [ "Perl", @@ -183,7 +188,6 @@ 11 ] ], - "id" : "010", "name" : "010" }, { @@ -205,7 +209,6 @@ "name" : "011" }, { - "name" : "012", "data" : [ [ "Perl", @@ -220,9 +223,11 @@ 11 ] ], - "id" : "012" + "id" : "012", + "name" : "012" }, { + "id" : "013", "data" : [ [ "Perl", @@ -237,10 +242,11 @@ 13 ] ], - "id" : "013", "name" : "013" }, { + "name" : "014", + "id" : "014", "data" : [ [ "Perl", @@ -254,9 +260,7 @@ "Blog", 15 ] - ], - "id" : "014", - "name" : "014" + ] }, { "name" : "015", @@ -277,8 +281,6 @@ "id" : "015" }, { - "name" : "016", - "id" : "016", "data" : [ [ "Perl", @@ -292,11 +294,11 @@ "Blog", 12 ] - ] + ], + "id" : "016", + "name" : "016" }, { - "name" : "017", - "id" : "017", "data" : [ [ "Perl", @@ -310,10 +312,11 @@ "Blog", 12 ] - ] + ], + "id" : "017", + "name" : "017" }, { - "id" : "018", "data" : [ [ "Perl", @@ -328,6 +331,7 @@ < |
