diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2020-09-15 16:03:28 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2020-09-15 16:03:28 +0100 |
| commit | 523483aac2851a2f9af2f416f4dacf7f579115fb (patch) | |
| tree | ce1c5b035582d3996245680fa101e56e6e5600f1 | |
| parent | 62703ba4f77e74b9fab081ff9a823c4e26361341 (diff) | |
| download | perlweeklychallenge-club-523483aac2851a2f9af2f416f4dacf7f579115fb.tar.gz perlweeklychallenge-club-523483aac2851a2f9af2f416f4dacf7f579115fb.tar.bz2 perlweeklychallenge-club-523483aac2851a2f9af2f416f4dacf7f579115fb.zip | |
- Added solutions by Abigail.
| -rw-r--r-- | challenge-078/abigail/node/ch-1.js | 52 | ||||
| -rw-r--r-- | challenge-078/abigail/node/ch-2.js | 33 | ||||
| -rwxr-xr-x | challenge-078/abigail/perl/ch-1.pl | 43 | ||||
| -rwxr-xr-x | challenge-078/abigail/perl/ch-2.pl | 42 | ||||
| -rwxr-xr-x | challenge-078/abigail/perl/test.pl | 44 | ||||
| -rw-r--r-- | stats/pwc-current.json | 161 | ||||
| -rw-r--r-- | stats/pwc-language-breakdown-summary.json | 70 | ||||
| -rw-r--r-- | stats/pwc-language-breakdown.json | 570 | ||||
| -rw-r--r-- | stats/pwc-leaders.json | 742 | ||||
| -rw-r--r-- | stats/pwc-summary-1-30.json | 98 | ||||
| -rw-r--r-- | stats/pwc-summary-121-150.json | 38 | ||||
| -rw-r--r-- | stats/pwc-summary-151-180.json | 112 | ||||
| -rw-r--r-- | stats/pwc-summary-181-210.json | 50 | ||||
| -rw-r--r-- | stats/pwc-summary-31-60.json | 52 | ||||
| -rw-r--r-- | stats/pwc-summary-61-90.json | 96 | ||||
| -rw-r--r-- | stats/pwc-summary-91-120.json | 28 | ||||
| -rw-r--r-- | stats/pwc-summary.json | 30 |
17 files changed, 1245 insertions, 1016 deletions
diff --git a/challenge-078/abigail/node/ch-1.js b/challenge-078/abigail/node/ch-1.js new file mode 100644 index 0000000000..eba11fd3b3 --- /dev/null +++ b/challenge-078/abigail/node/ch-1.js @@ -0,0 +1,52 @@ +// +// Exercise: +// You are given an array @A containing distinct integers. +// Write a script to find all leader elements in the array @A. +// Print (0) if none found. An element is leader if it is greater +// than all the elements to its right side. +// + +// +// Note: +// - The only way no leader element can be found is if the array is empty. +// - We will read the array from STDIN. +// + +// +// Read a line from STDIN, turn it into a string, strip off the +// trailing newline (and any leading or trailing whitespace), +// and then split in on spaces. Store the result into an array "arry". +// +let fs = require ("fs"); +let line = fs . readFileSync (0) . toString () . trim (); +let arry = line . split (" "); + +if (line . length == 0) { + // + // Special case, if the line is empty, output 0 + // + console . log (0); +} +else { + // + // Iterate backwards over the array. Keep track of the largest + // element so far in an array 'out'. If we find a new largest + // element, put this first in 'out' (so, the largest element + // seen so far is always in 'out [0]'. + // + let out = [arry [arry . length - 1]]; + for (let i = arry . length - 2; i >= 0; i --) { + // + // Note that we have strings in arry (and hence, out). + // An unary + casts them to numbers. + // + if (+arry [i] > +out [0]) { + out . unshift (arry [i]); + } + } + + // + // Print the result. + // + console . log (out . join (" ")); +} diff --git a/challenge-078/abigail/node/ch-2.js b/challenge-078/abigail/node/ch-2.js new file mode 100644 index 0000000000..6d76c9aa91 --- /dev/null +++ b/challenge-078/abigail/node/ch-2.js @@ -0,0 +1,33 @@ +// +// Exercise: +// +// You are given array @A containing positive numbers and @B containing +// one or more indices from the array @A. +// Write a script to left rotate @A so that the number at the first index +// of @B becomes the first element in the array. Similary, left rotate @A +// again so that the number at the second index of @B becomes the first +// element in the array. +// +// We will be reading the arrays from STDIN -- @A is one the first +// line, @B is on the second line. +// + +// +// Read two lines from STDIN, turn it into a string, strip off the +// trailing newline (and any leading or trailing whitespace), +// and then split in on spaces. Store the result into an arrays A and B. +// +let fs = require ("fs"); +let lines = fs . readFileSync (0) . toString () . split ("\n"); +let A = lines [0] . trim () . split (" "); +let B = lines [1] . trim () . split (" "); + + +// +// Iterate over the array B, and print the slices of A. +// +for (let i = 0; i < B . length; i ++) { + let index = +B [i]; + console . log (A . slice ( index) . join (" ") + " " + + A . slice (0, index) . join (" ")); +} diff --git a/challenge-078/abigail/perl/ch-1.pl b/challenge-078/abigail/perl/ch-1.pl new file mode 100755 index 0000000000..e74cbbb0c4 --- /dev/null +++ b/challenge-078/abigail/perl/ch-1.pl @@ -0,0 +1,43 @@ +#!/opt/perl/bin/perl + +# +# Exercise: +# You are given an array @A containing distinct integers. +# Write a script to find all leader elements in the array @A. +# Print (0) if none found. An element is leader if it is greater +# than all the elements to its right side. +# + +# +# Note: +# - The only way no leader element can be found is if the array is empty. +# - We will read the array from STDIN. +# + +use 5.032; + +use strict; +use warnings; +no warnings 'syntax'; + +use experimental 'signatures'; + +my $max; + +# +# Read the input, extract integers, and store them in @A. +# If the input is empty, print 0 and exit. +# +say (0), exit unless my @A = <> =~ /[0-9]+/g; + +local $, = " "; + +# +# Reverse the array, and extract each element which was larger +# than any seen before (keep state in $max), then reverse it +# again before printing. +# + +say reverse + grep {!defined $max || $_ > $max ? do {$max = $_; 1} : 0} + reverse @A; diff --git a/challenge-078/abigail/perl/ch-2.pl b/challenge-078/abigail/perl/ch-2.pl new file mode 100755 index 0000000000..80e8f4907d --- /dev/null +++ b/challenge-078/abigail/perl/ch-2.pl @@ -0,0 +1,42 @@ +#!/opt/perl/bin/perl + +# +# Exercise: +# +# You are given array @A containing positive numbers and @B containing +# one or more indices from the array @A. +# Write a script to left rotate @A so that the number at the first index +# of @B becomes the first element in the array. Similary, left rotate @A +# again so that the number at the second index of @B becomes the first +# element in the array. +# + +# +# We will be reading the arrays from STDIN -- @A is one the first +# line, @B is on the second line. +# + +use 5.032; + +use strict; +use warnings; +no warnings 'syntax'; + +use experimental 'signatures'; + +# +# Read @A and @B +# +chomp (my @A = split / / => scalar <>); +chomp (my @B = split / / => scalar <>); + +# +# Print the rotations. +# +foreach my $index (@B) { + local $, = " "; + say @A [$index .. @A - 1, 0 .. $index - 1]; +} + + +__END__ diff --git a/challenge-078/abigail/perl/test.pl b/challenge-078/abigail/perl/test.pl new file mode 100755 index 0000000000..115e570c62 --- /dev/null +++ b/challenge-078/abigail/perl/test.pl @@ -0,0 +1,44 @@ +#!/opt/perl/bin/perl + +# +# Test the solutions. Either call it with the directory name you +# want to test in, or call it as "../test.pl" from within the directory. +# + +use 5.032; + +use strict; +use warnings; +no warnings 'syntax'; + +chdir shift if @ARGV; + +use experimental 'signatures'; + +use Test::More; + +my %languages = ( + Perl => ["/opt/perl/bin/perl" => 'pl'], + JavaScript => ["/usr/local/bin/node" => 'js'], +); + + +my @inputs = <input*>; + +foreach my $language (sort keys %languages) { + my ($exe, $ext) = @{$languages {$language}}; + next unless -r "solution.$ext"; + subtest $language => sub { + foreach my $input (@inputs) { + my $output_exp = ($input =~ s/input/output/r) . ".exp"; + my $exp = `cat $output_exp`; + my $got = `$exe ./solution.$ext < $input`; + is $got, $exp, $input; + } + } +} + +done_testing; + + +__END__ diff --git a/stats/pwc-current.json b/stats/pwc-current.json index abb7f8c305..bb94e389c4 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,33 +1,46 @@ { - "title" : { - "text" : "Perl Weekly Challenge - 078" + "xAxis" : { + "type" : "category" }, - "tooltip" : { - "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>", - "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>", - "followPointer" : 1 + "chart" : { + "type" : "column" }, - "yAxis" : { - "title" : { - "text" : "Total Solutions" + "plotOptions" : { + "series" : { + "dataLabels" : { + "enabled" : 1, + "format" : "{point.y}" + }, + "borderWidth" : 0 } }, - "xAxis" : { - "type" : "category" + "legend" : { + "enabled" : 0 }, "drilldown" : { "series" : [ { - "id" : "Alexander Pankoff", - "name" : "Alexander Pankoff", + "id" : "Abigail", "data" : [ [ "Perl", 2 ] - ] + ], + "name" : "Abigail" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Alexander Pankoff", + "name" : "Alexander Pankoff" }, { + "name" : "Andinus", "data" : [ [ "Perl", @@ -38,11 +51,9 @@ 2 ] ], - "name" : "Andinus", "id" : "Andinus" }, { - "name" : "Andrew Shitov", "id" : "Andrew Shitov", "data" : [ [ @@ -53,37 +64,38 @@ "Blog", 1 ] - ] + ], + "name" : "Andrew Shitov" }, { - "name" : "Anton Fedotov", - "id" : "Anton Fedotov", "data" : [ [ "Perl", 2 ] - ] + ], + "id" : "Anton Fedotov", + "name" : "Anton Fedotov" }, { - "id" : "Bob Lied", "name" : "Bob Lied", "data" : [ [ "Perl", 2 ] - ] + ], + "id" : "Bob Lied" }, { - "name" : "Dave Cross", - "id" : "Dave Cross", "data" : [ [ "Perl", 2 ] - ] + ], + "id" : "Dave Cross", + "name" : "Dave Cross" }, { "name" : "Dave Jacoby", @@ -96,24 +108,24 @@ ] }, { + "name" : "James Smith", + "id" : "James Smith", "data" : [ [ "Perl", 2 ] - ], - "name" : "James Smith", - "id" : "James Smith" + ] }, { + "name" : "Jason Messer", + "id" : "Jason Messer", "data" : [ [ "Raku", 2 ] - ], - "id" : "Jason Messer", - "name" : "Jason Messer" + ] }, { "data" : [ @@ -122,8 +134,8 @@ 2 ] ], - "name" : "Mark Anderson", - "id" : "Mark Anderson" + "id" : "Mark Anderson", + "name" : "Mark Anderson" }, { "data" : [ @@ -160,18 +172,18 @@ "name" : "Roger Bell_West" }, { - "id" : "Simon Proctor", - "name" : "Simon Proctor", "data" : [ [ "Raku", 2 ] - ] + ], + "id" : "Simon Proctor", + "name" : "Simon Proctor" }, { - "id" : "Ulrich Rieke", "name" : "Ulrich Rieke", + "id" : "Ulrich Rieke", "data" : [ [ "Perl", @@ -184,6 +196,8 @@ ] }, { + "name" : "Walt Mankowski", + "id" : "Walt Mankowski", "data" : [ [ "Perl", @@ -193,50 +207,50 @@ "Blog", 1 ] - ], - "name" : "Walt Mankowski", - "id" : "Walt Mankowski" + ] } ] }, - "plotOptions" : { - "series" : { - "dataLabels" : { - "format" : "{point.y}", - "enabled" : 1 - }, - "borderWidth" : 0 - } + "tooltip" : { + "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>", + "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>", + "followPointer" : 1 }, - "chart" : { - "type" : "column" + "title" : { + "text" : "Perl Weekly Challenge - 078" }, "series" : [ { + "name" : "Perl Weekly Challenge - 078", "data" : [ { "y" : 2, + "drilldown" : "Abigail", + "name" : "Abigail" + }, + { + "y" : 2, "name" : "Alexander Pankoff", "drilldown" : "Alexander Pankoff" }, { - "drilldown" : "Andinus", "name" : "Andinus", + "drilldown" : "Andinus", "y" : 4 }, { "y" : 3, - "name" : "Andrew Shitov", - "drilldown" : "Andrew Shitov" + "drilldown" : "Andrew Shitov", + "name" : "Andrew Shitov" }, { - "drilldown" : "Anton Fedotov", "name" : "Anton Fedotov", + "drilldown" : "Anton Fedotov", "y" : 2 }, { - "name" : "Bob Lied", "y" : 2, + "name" : "Bob Lied", "drilldown" : "Bob Lied" }, { @@ -251,23 +265,23 @@ }, { "drilldown" : "James Smith", - "y" : 2, - "name" : "James Smith" + "name" : "James Smith", + "y" : 2 }, { "name" : "Jason Messer", - "y" : 2, - "drilldown" : "Jason Messer" + "drilldown" : "Jason Messer", + "y" : 2 }, { - "drilldown" : "Mark Anderson", "y" : 2, - "name" : "Mark Anderson" + "name" : "Mark Anderson", + "drilldown" : "Mark Anderson" }, { "y" : 2, - "name" : "Markus Holzer", - "drilldown" : "Markus Holzer" + "drilldown" : "Markus Holzer", + "name" : "Markus Holzer" }, { "drilldown" : "Niels van Dijke", @@ -285,24 +299,25 @@ "drilldown" : "Simon Proctor" }, { - "drilldown" : "Ulrich Rieke", + "y" : 4, "name" : "Ulrich Rieke", - "y" : 4 + "drilldown" : "Ulrich Rieke" }, { - "y" : 3, + "drilldown" : "Walt Mankowski", "name" : "Walt Mankowski", - "drilldown" : "Walt Mankowski" + "y" : 3 } ], - "colorByPoint" : 1, - "name" : "Perl Weekly Challenge - 078" + "colorByPoint" : 1 } ], - "subtitle" : { - "text" : "[Champions: 16] Last updated at 2020-09-15 12:43:48 GMT" + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } }, - "legend" : { - "enabled" : 0 + "subtitle" : { + "text" : "[Champions: 17] Last updated at 2020-09-15 15:02:22 GMT" } } diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index 2146972b3f..13af80144e 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -1,47 +1,27 @@ { - "yAxis" : { - "title" : { - "text" : null - }, - "min" : 0 - }, - "chart" : { - "type" : "column" - }, "xAxis" : { - "type" : "category", "labels" : { "style" : { - "fontSize" : "13px", - "fontFamily" : "Verdana, sans-serif" + "fontFamily" : "Verdana, sans-serif", + "fontSize" : "13px" } - } - }, - "tooltip" : { - "pointFormat" : "<b>{point.y:.0f}</b>" - }, - "title" : { - "text" : "Perl Weekly Challenge Contributions [2019 - 2020]" - }, - "legend" : { - "enabled" : "false" - }, - "subtitle" : { - "text" : "Last updated at 2020-09-15 12:43:48 GMT" + }, + "type" : "category" }, "series" : [ { + "name" : "Contributions", "dataLabels" : { "align" : "right", + "y" : 10, "color" : "#FFFFFF", - "enabled" : "true", - "rotation" : -90, "format" : "{point.y:.0f}", - "y" : 10, + "rotation" : -90, "style" : { - "fontFamily" : "Verdana, sans-serif", - "fontSize" : "13px" - } + "fontSize" : "13px", + "fontFamily" : "Verdana, sans-serif" + }, + "enabled" : "true" }, "data" : [ [ @@ -50,14 +30,34 @@ ], [ "Perl", - 3273 + 3275 ], [ "Raku", 2134 ] - ], - "name" : "Contributions" + ] } - ] + ], + "yAxis" : { + "title" : { + "text" : null + }, + "min" : 0 + }, + "title" : { + "text" : "Perl Weekly Challenge Contributions [2019 - 2020]" + }, + "subtitle" : { + "text" : "Last updated at 2020-09-15 15:02:22 GMT" + }, + "chart" : { + "type" : "column" + }, + "legend" : { + "enabled" : "false" + }, + "tooltip" : { + "pointFormat" : "<b>{point.y:.0f}</b>" + } } diff --git a/stats/pwc-language-breakdown.json b/stats/pwc-language-breakdown.json index d4478a152e..e477507e1e 100644 --- a/stats/pwc-language-breakdown.json +++ b/stats/pwc-language-breakdown.json @@ -1,25 +1,25 @@ { - "title" : { - "text" : "Perl Weekly Challenge Language" + "xAxis" : { + "type" : "category" }, - "tooltip" : { - "followPointer" : "true", - "pointFormat" : "<span style=\"color:{point.color}\">Challenge {point.name}</span>: <b>{point.y:f}</b><br/>", - "headerFormat" : "<span style=\"font-size:11px\"></span>" + "legend" : { + "enabled" : "false" }, - "yAxis" : { - "title" : { - "text" : "Total Solutions" + "plotOptions" : { + "series" : { + "borderWidth" : 0, + "dataLabels" : { + "format" : "{point.y}", + "enabled" : 1 + } } }, - "xAxis" : { - "type" : "category" + "chart" : { + "type" : "column" }, "drilldown" : { "series" : [ { - "name" : "001", - "id" : "001", "data" : [ [ "Perl", @@ -33,9 +33,13 @@ "Blog", 11 ] - ] + ], + "id" : "001", + "name" : "001" }, { + "name" : "002", + "id" : "002", "data" : [ [ "Perl", @@ -49,12 +53,9 @@ "Blog", 10 ] - ], - "id" : "002", - "name" : "002" + ] }, { - "id" : "003", "name" : "003", "data" : [ [ @@ -69,9 +70,12 @@ "Blog", 9 ] - ] + ], + "id" : "003" }, { + "name" : "004", + "id" : "004", "data" : [ [ "Perl", @@ -85,13 +89,10 @@ "Blog", 10 ] - ], - "id" : "004", - "name" : "004" + ] }, { "id" : "005", - "name" : "005", "data" : [ [ "Perl", @@ -105,7 +106,8 @@ "Blog", 12 ] - ] + ], + "name" : "005" }, { "data" : [ @@ -122,11 +124,10 @@ 7 ] ], - "name" : "006", - "id" : "006" + "id" : "006", + "name" : "006" }, { - "id" : "007", "name" : "007", "data" : [ [ @@ -141,7 +142,8 @@ "Blog", 10 ] - ] + ], + "id" : "007" }, { "name" : "008", @@ -162,7 +164,6 @@ ] }, { - "name" : "009", "id" : "009", "data" : [ [ @@ -177,9 +178,11 @@ "Blog", 13 ] - ] + ], + "name" : "009" }, { + "name" : "010", "data" : [ [ "Perl", @@ -194,11 +197,9 @@ 11 ] ], - "name" : "010", "id" : "010" }, { - "id" : "011", "name" : "011", "data" : [ [ @@ -213,11 +214,11 @@ "Blog", 10 ] - ] + ], + "id" : "011" }, { "id" : "012", - "name" : "012", "data" : [ [ "Perl", @@ -231,9 +232,11 @@ "Blog", 11 ] - ] + ], + "name" : "012" }, { + "name" : "013", "data" : [ [ "Perl", @@ -248,11 +251,9 @@ 13 ] ], - "name" : "013", "id" : "013" }, { - "name" : "014", "id" : "014", "data" : [ [ @@ -267,9 +268,12 @@ "Blog", 15 ] - ] + ], + "name" : "014" }, { + "name" : "015", + "id" : "015", "data" : [ [ "Perl", @@ -283,9 +287,7 @@ "Blog", 15 ] - ], - "name" : "015", - "id" : "015" + ] }, { "name" : "016", @@ -307,7 +309,6 @@ }, { "name" : "017", - "id" : "017", "data" : [ [ "Perl", @@ -321,11 +322,12 @@ "Blog", 12 ] - ] + ], + "id" : "017" }, { - "id" : "018", "name" : "018", + "id" : "018", "data" : [ [ "Perl", @@ -342,6 +344,7 @@ ] }, { + "id" : "019", "data" : [ [ "Perl", @@ -356,12 +359,10 @@ 13 ] ], - "name" : "019", - "id" : "019" + "name" : "019" }, { "name" : "020", - "id" : "020", "data" : [ [ "Perl", @@ -375,10 +376,10 @@ "Blog", 13 ] - ] + ], + "id" : "020" }, { - "name" : "021", "id" : "021", "data" : [ [ @@ -393,11 +394,10 @@ "Blog", 10 ] - ] + ], + "name" : "021" }, { - "name" : "022", - "id" : "022", "data" : [ [ "Perl", @@ -411,11 +411,11 @@ "Blog", 10 ] - ] + ], + "id" : "022", + "name" : "022" }, { - "name" : "023", - "id" : "023", "data" : [ [ "Perl", @@ -429,7 +429,9 @@ "Blog", 12 ] - ] + ], + "id" : "023", + "name" : "023" }, { "data" : [ @@ -451,7 +453,6 @@ }, { "id" : "025", - "name" : "025", "data" : [ [ "Perl", @@ -465,9 +466,11 @@ "Blog", 12 ] - ] + ], + "name" : "025" }, { + "name" : "026", "data" : [ [ "Perl", @@ -482,8 +485,7 @@ 10 ] ], - "id" : "026", - "name" : "026" + "id" : "026" }, { "data" : [ @@ -522,6 +524,7 @@ "name" : "028" }, { + "name" : "029", "data" : [ [ "Perl", @@ -536,12 +539,10 @@ 12 ] ], - "id" : "029", - "name" : "029" + "id" : "029" }, { "name" : "030", - "id" : "030", "data" : [ [ "Perl", @@ -555,9 +556,11 @@ "Blog", 10 ] - ] + ], + "id" : "030" }, { + "id" : "031", "data" : [ [ "Perl", @@ -572,7 +575,6 @@ 9 ] ], - "id" : "031", "name" : "031" }, { @@ -590,10 +592,11 @@ 10 ] |
