diff options
| author | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-01-26 17:21:13 +0000 |
|---|---|---|
| committer | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-01-26 17:21:13 +0000 |
| commit | 92bb6e8cd849038dcb7cfca69fab6413225cd19a (patch) | |
| tree | 2f079b9c5cbcc86cd857b2c77fe3a3080664e7cc | |
| parent | 8577a80498e051383b46cc325a26efed3cfb02b6 (diff) | |
| download | perlweeklychallenge-club-92bb6e8cd849038dcb7cfca69fab6413225cd19a.tar.gz perlweeklychallenge-club-92bb6e8cd849038dcb7cfca69fab6413225cd19a.tar.bz2 perlweeklychallenge-club-92bb6e8cd849038dcb7cfca69fab6413225cd19a.zip | |
- Added solutions by Athanasius.
- Added solutions by Dave Jacoby.
- Added solutions by Arne Sommer.
- Added blog post by Roger Bell_West.
- Added solutions by Wanderdoc.
25 files changed, 2908 insertions, 2715 deletions
diff --git a/challenge-305/wanderdoc/perl/ch-1.pl b/challenge-305/wanderdoc/perl/ch-1.pl new file mode 100755 index 0000000000..fe80870d64 --- /dev/null +++ b/challenge-305/wanderdoc/perl/ch-1.pl @@ -0,0 +1,67 @@ +#!perl
+use strict;
+use warnings FATAL => qw(all);
+
+=prompt
+You are given a binary array.
+
+Write a script to return an array of booleans where the partial binary number up to that point is prime.
+Example 1
+
+Input: @binary = (1, 0, 1)
+Output: (false, true, true)
+
+Sub-arrays (base-10):
+(1): 1 - not prime
+(1, 0): 2 - prime
+(1, 0, 1): 5 - prime
+
+Example 2
+
+Input: @binary = (1, 1, 0)
+Output: (false, true, false)
+
+Sub-arrays (base-10):
+(1): 1 - not prime
+(1, 1): 3 - prime
+(1, 1, 0): 6 - not prime
+
+Example 3
+
+Input: @binary = (1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1)
+Output: (false, true, true, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, true)
+
+=cut
+
+use Math::Prime::Util qw(primes);
+use constant { true => 1, false => 0 };
+use Test2::V0 -no_srand => 1;
+
+
+
+is(bin_prefix(1, 0, 1), [false, true, true], 'Example 1');
+is(bin_prefix(1, 1, 0), [false, true, false], 'Example 2');
+is(bin_prefix(1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1),
+ [false, true, true, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, true], 'Example 3');
+done_testing();
+
+
+
+sub bin_prefix
+{
+ my @arr = @_;
+ my $max = oct("0b" . '1' x scalar(@arr));
+ my %primes_bin = map { sprintf("%b", $_) => true }
+ @{ primes($max) };
+ my @output;
+ for my $idx ( 0 .. $#arr )
+ {
+ push @output,
+ $primes_bin{ join('', @arr[0 .. $idx]) } // false;
+ }
+ return \@output;
+}
+
+
+
+
diff --git a/challenge-305/wanderdoc/perl/ch-2.pl b/challenge-305/wanderdoc/perl/ch-2.pl new file mode 100755 index 0000000000..40bf209f07 --- /dev/null +++ b/challenge-305/wanderdoc/perl/ch-2.pl @@ -0,0 +1,50 @@ +#!perl
+use strict;
+use warnings FATAL => qw(all);
+
+=prompt
+You are given a list of words and alien dictionary character order.
+
+Write a script to sort lexicographically the given list of words based on the alien dictionary characters.
+Example 1
+
+Input: @words = ("perl", "python", "raku")
+ @alien = qw/h l a b y d e f g i r k m n o p q j s t u v w x c z/
+Output: ("raku", "python", "perl")
+
+Example 2
+
+Input: @words = ("the", "weekly", "challenge")
+ @alien = qw/c o r l d a b t e f g h i j k m n p q s w u v x y z/
+Output: ("challenge", "the", "weekly")
+=cut
+
+use Test2::V0 -no_srand => 1;
+
+is(custom_sort(["perl", "python", "raku"], [qw/h l a b y d e f g i r k m n o p q j s t u v w x c z/]), ["raku", "python", "perl"], 'Example 1');
+is(custom_sort(["the", "weekly", "challenge"], [qw/c o r l d a b t e f g h i j k m n p q s w u v x y z/]), ["challenge", "the", "weekly"], 'Example 2');
+done_testing();
+
+sub custom_sort
+{
+ my ($words_aref, $letters_aref) = @_;
+ my $counter = 0;
+ my %points = map {$_ => $counter++} @$letters_aref;
+
+ @$words_aref = sort
+ {
+ my @left = split(//, $a);
+ my @right = split(//, $b);
+ my $max_len = length($a) > length($b) ? length($a) : length($b);
+ my $max_idx = $max_len - 1;
+ for my $idx ( 0 .. $max_idx )
+ {
+ return -1 if not defined $left[$idx];
+ return 1 if not defined $right[$idx];
+ next if $left[$idx] eq $right[$idx];
+ return $points{$left[$idx]} <=> $points{$right[$idx]};
+ }
+ }
+ @$words_aref;
+ return $words_aref;
+}
\ No newline at end of file diff --git a/stats/pwc-current.json b/stats/pwc-current.json index 746d3f65c9..06e03180bd 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,24 +1,8 @@ { - "xAxis" : { - "type" : "category" - }, - "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 - }, - "plotOptions" : { - "series" : { - "borderWidth" : 0, - "dataLabels" : { - "enabled" : 1, - "format" : "{point.y}" - } - } - }, "drilldown" : { "series" : [ { + "id" : "Ali Moradi", "data" : [ [ "Perl", @@ -29,7 +13,6 @@ 1 ] ], - "id" : "Ali Moradi", "name" : "Ali Moradi" }, { @@ -43,57 +26,98 @@ ] }, { - "id" : "Bob Lied", + "id" : "Arne Sommer", + "data" : [ + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ], + "name" : "Arne Sommer" + }, + { + "name" : "Athanasius", "data" : [ [ "Perl", 2 + ], + [ + "Raku", + 2 ] ], - "name" : "Bob Lied" + "id" : "Athanasius" }, { - "id" : "David Ferrone", + "name" : "Bob Lied", "data" : [ [ "Perl", 2 ] ], - "name" : "David Ferrone" + "id" : "Bob Lied" + }, + { + "name" : "Dave Jacoby", + "id" : "Dave Jacoby", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ] + }, + { + "name" : "David Ferrone", + "id" : "David Ferrone", + "data" : [ + [ + "Perl", + 2 + ] + ] }, { "name" : "E. Choroba", + "id" : "E. Choroba", "data" : [ [ "Perl", 2 ] - ], - "id" : "E. Choroba" + ] }, { - "name" : "Feng Chang", + "id" : "Feng Chang", "data" : [ [ "Raku", 2 ] ], - "id" : "Feng Chang" + "name" : "Feng Chang" }, { "name" : "Jeffrey \"japhy\" Pinyan", + "id" : "Jeffrey \"japhy\" Pinyan", "data" : [ [ "Perl", 2 ] - ], - "id" : "Jeffrey \"japhy\" Pinyan" + ] }, { - "name" : "Jorg Sommrey", "id" : "Jorg Sommrey", "data" : [ [ @@ -104,20 +128,20 @@ "Blog", 1 ] - ] + ], + "name" : "Jorg Sommrey" }, { + "name" : "Lubos Kolouch", "data" : [ [ "Perl", 2 ] ], - "id" : "Lubos Kolouch", - "name" : "Lubos Kolouch" + "id" : "Lubos Kolouch" }, { - "id" : "Luca Ferrari", "data" : [ [ "Raku", @@ -128,31 +152,31 @@ 10 ] ], + "id" : "Luca Ferrari", "name" : "Luca Ferrari" }, { - "id" : "Mark Anderson", + "name" : "Mark Anderson", "data" : [ [ "Raku", 2 ] ], - "name" : "Mark Anderson" + "id" : "Mark Anderson" }, { "name" : "Niels van Dijke", - "id" : "Niels van Dijke", "data" : [ [ "Perl", 2 ] - ] + ], + "id" : "Niels van Dijke" }, { "name" : "Peter Campbell Smith", - "id" : "Peter Campbell Smith", "data" : [ [ "Perl", @@ -162,20 +186,20 @@ "Blog", 1 ] - ] + ], + "id" : "Peter Campbell Smith" }, { - "name" : "Peter Meszaros", "id" : "Peter Meszaros", "data" : [ [ "Perl", 2 ] - ] + ], + "name" : "Peter Meszaros" }, { - "id" : "Robbie Hatley", "data" : [ [ "Perl", @@ -186,20 +210,20 @@ 1 ] ], + "id" : "Robbie Hatley", "name" : "Robbie Hatley" }, { - "name" : "Robert Ransbottom", - "id" : "Robert Ransbottom", "data" : [ [ "Raku", 2 ] - ] + ], + "id" : "Robert Ransbottom", + "name" : "Robert Ransbottom" }, { - "name" : "Roger Bell_West", "id" : "Roger Bell_West", "data" : [ [ @@ -209,11 +233,17 @@ [ "Raku", 2 + ], + [ + "Blog", + 1 ] - ] + ], + "name" : "Roger Bell_West" }, { "name" : "Thomas Kohler", + "id" : "Thomas Kohler", "data" : [ [ "Perl", @@ -223,11 +253,9 @@ "Blog", 2 ] - ], - "id" : "Thomas Kohler" + ] }, { - "id" : "Ulrich Rieke", "data" : [ [ "Perl", @@ -238,11 +266,10 @@ 2 ] ], + "id" : "Ulrich Rieke", "name" : "Ulrich Rieke" }, { - "name" : "W. Luis Mochan", - "id" : "W. Luis Mochan", "data" : [ [ "Perl", @@ -252,53 +279,81 @@ "Blog", 1 ] - ] + ], + "id" : "W. Luis Mochan", + "name" : "W. Luis Mochan" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Wanderdoc", + "name" : "Wanderdoc" } ] }, - "title" : { - "text" : "The Weekly Challenge - 305" - }, - "legend" : { - "enabled" : 0 + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } }, "series" : [ { + "colorByPoint" : 1, + "name" : "The Weekly Challenge - 305", "data" : [ { - "name" : "Ali Moradi", + "y" : 3, "drilldown" : "Ali Moradi", - "y" : 3 + "name" : "Ali Moradi" }, { "y" : 2, - "drilldown" : "Andreas Mahnke", - "name" : "Andreas Mahnke" + "name" : "Andreas Mahnke", + "drilldown" : "Andreas Mahnke" + }, + { + "y" : 3, + "drilldown" : "Arne Sommer", + "name" : "Arne Sommer" + }, + { + "name" : "Athanasius", + "drilldown" : "Athanasius", + "y" : 4 }, { - "name" : "Bob Lied", "y" : 2, - "drilldown" : "Bob Lied" + "drilldown" : "Bob Lied", + "name" : "Bob Lied" + }, + { + "y" : 3, + "name" : "Dave Jacoby", + "drilldown" : "Dave Jacoby" }, { - "drilldown" : "David Ferrone", "y" : 2, - "name" : "David Ferrone" + "name" : "David Ferrone", + "drilldown" : "David Ferrone" }, { "name" : "E. Choroba", - "y" : 2, - "drilldown" : "E. Choroba" + "drilldown" : "E. Choroba", + "y" : 2 }, { + "name" : "Feng Chang", "drilldown" : "Feng Chang", - "y" : 2, - "name" : "Feng Chang" + "y" : 2 }, { - "drilldown" : "Jeffrey \"japhy\" Pinyan", "y" : 2, - "name" : "Jeffrey \"japhy\" Pinyan" + "name" : "Jeffrey \"japhy\" Pinyan", + "drilldown" : "Jeffrey \"japhy\" Pinyan" }, { "y" : 3, @@ -307,76 +362,97 @@ }, { "y" : 2, - "drilldown" : "Lubos Kolouch", - "name" : "Lubos Kolouch" + "name" : "Lubos Kolouch", + "drilldown" : "Lubos Kolouch" }, { - "name" : "Luca Ferrari", "drilldown" : "Luca Ferrari", + "name" : "Luca Ferrari", "y" : 12 }, { "name" : "Mark Anderson", - "y" : 2, - "drilldown" : "Mark Anderson" + "drilldown" : "Mark Anderson", + "y" : 2 }, { - "drilldown" : "Niels van Dijke", "y" : 2, + "drilldown" : "Niels van Dijke", "name" : "Niels van Dijke" }, { "drilldown" : "Peter Campbell Smith", - "y" : 3, - "name" : "Peter Campbell Smith" + "name" : "Peter Campbell Smith", + "y" : 3 }, { - "name" : "Peter Meszaros", "drilldown" : "Peter Meszaros", + "name" : "Peter Meszaros", "y" : 2 }, { - "name" : "Robbie Hatley", "y" : 3, + "name" : "Robbie Hatley", "drilldown" : "Robbie Hatley" }, { - "name" : "Robert Ransbottom", "y" : 2, - "drilldown" : "Robert Ransbottom" + "drilldown" : "Robert Ransbottom", + "name" : "Robert Ransbottom" }, { "name" : "Roger Bell_West", - "y" : 4, - "drilldown" : "Roger Bell_West" + "drilldown" : "Roger Bell_West", + "y" : 5 }, { "drilldown" : "Thomas Kohler", - "y" : 4, - "name" : "Thomas Kohler" + "name" : "Thomas Kohler", + "y" : 4 }, { - "name" : "Ulrich Rieke", "y" : 4, + "name" : "Ulrich Rieke", "drilldown" : "Ulrich Rieke" }, { - "name" : "W. Luis Mochan", "y" : 3, - "drilldown" : "W. Luis Mochan" + "drilldown" : "W. Luis Mochan", + "name" : "W. Luis Mochan" + }, + { + "y" : 2, + "name" : "Wanderdoc", + "drilldown" : "Wanderdoc" } - ], - "colorByPoint" : 1, - "name" : "The Weekly Challenge - 305" + ] } ], - "yAxis" : { - "title" : { - "text" : "Total Solutions" + "xAxis" : { + "type" : "category" + }, + "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" : { + "enabled" : 1, + "format" : "{point.y}" + } } }, "subtitle" : { - "text" : "[Champions: 20] Last updated at 2025-01-25 17:31:47 GMT" + "text" : "[Champions: 24] Last updated at 2025-01-26 17:20:53 GMT" + }, + "legend" : { + "enabled" : 0 + }, + "title" : { + "text" : "The Weekly Challenge - 305" }, "chart" : { "type" : "column" diff --git a/stats/pwc-language-breakdown-2019.json b/stats/pwc-language-breakdown-2019.json index e571b6ec78..7ca7a2c49f 100644 --- a/stats/pwc-language-breakdown-2019.json +++ b/stats/pwc-language-breakdown-2019.json @@ -1,11 +1,16 @@ { + "tooltip" : { + "pointFormat" : "<span style=\"color:{point.color}\">Challenge {point.name}</span>: <b>{point.y:f}</b><br/>", + "followPointer" : "true", + "headerFormat" : "<span style=\"font-size:11px\"></span>" + }, "xAxis" : { "type" : "category" }, - "tooltip" : { - "followPointer" : "true", - "headerFormat" : "<span style=\"font-size:11px\"></span>", - "pointFormat" : "<span style=\"color:{point.color}\">Challenge {point.name}</span>: <b>{point.y:f}</b><br/>" + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } }, "drilldown" : { "series" : [ @@ -46,8 +51,6 @@ "id" : "040" }, { - "name" : "039", - "id" : "039", "data" : [ [ "Perl", @@ -61,10 +64,11 @@ "Blog", 12 ] - ] + ], + "id" : "039", + "name" : "039" }, { - "name" : "038", "id" : "038", "data" : [ [ @@ -79,7 +83,8 @@ "Blog", 12 ] - ] + ], + "name" : "038" }, { "name" : "037", @@ -118,7 +123,7 @@ "name" : "036" }, { - "id" : "035", + "name" : "035", "data" : [ [ "Perl", @@ -133,10 +138,9 @@ 9 ] ], - "name" : "035" + "id" : "035" }, { - "id" : "034", "data" : [ [ "Perl", @@ -151,11 +155,11 @@ 11 ] ], + "id" : "034", "name" : "034" }, { "name" : "033", - "id" : "033", "data" : [ [ "Perl", @@ -169,9 +173,11 @@ "Blog", 10 ] - ] + ], + "id" : "033" }, { + "name" : "032", "data" : [ [ "Perl", @@ -186,8 +192,7 @@ 10 ] ], - "id" : "032", - "name" : "032" + "id" : "032" }, { "name" : "031", @@ -208,7 +213,6 @@ ] }, { - "id" : "030", "data" : [ [ "Perl", @@ -223,10 +227,12 @@ 10 ] ], + "id" : "030", "name" : "030" }, { "name" : "029", + "id" : "029", "data" : [ [ "Perl", @@ -240,12 +246,10 @@ "Blog", 12 ] - ], - "id" : "029" + ] }, { "name" : "028", - "id" : "028", "data" : [ [ "Perl", @@ -259,11 +263,11 @@ "Blog", 9 ] - ] + ], + "id" : "028" }, { "name" : "027", - "id" : "027", "data" : [ [ "Perl", @@ -277,11 +281,11 @@ "Blog", 9 ] - ] + ], + "id" : "027" }, { "name" : "026", - "id" : "026", "data" : [ [ "Perl", @@ -295,11 +299,11 @@ "Blog", 10 ] - ] + ], + "id" : "026" }, { "name" : "025", - "id" : "025", "data" : [ [ "Perl", @@ -313,11 +317,10 @@ "Blog", 12 ] - ] + ], + "id" : "025" }, { - "name" : "024", - "id" : "024", "data" : [ [ "Perl", @@ -331,7 +334,9 @@ "Blog", 11 ] - ] + ], + "id" : "024", + "name" : "024" }, { "name" : "023", @@ -353,7 +358,6 @@ }, { "name" : "022", - "id" : "022", "data" : [ [ "Perl", @@ -367,9 +371,11 @@ "Blog", 10 ] - ] + ], + "id" : "022" }, { + "name" : "021", "data" : [ [ "Perl", @@ -384,8 +390,7 @@ 10 ] ], - "id" : "021", - "name" : "021" + "id" : "021" }, { "name" : "020", @@ -406,6 +411,8 @@ "id" : "020" }, { + "name" : "019", + "id" : "019", "data" : [ [ "Perl", @@ -419,11 +426,11 @@ "Blog", 13 ] - ], - "id" : "019", - "name" : "019" + ] }, { + "name" : "018", + "id" : "018", "data" : [ [ "Perl", @@ -437,9 +444,7 @@ "Blog", 14 ] - ], - "id" : "018", - "name" : "018" + ] }, { "name" : "017", @@ -460,7 +465,7 @@ ] }, { - "name" : "016", + "id" : "016", "data" : [ [ "Perl", @@ -475,10 +480,10 @@ 13 ] ], - "id" : "016" + "name" : "016" }, { - "name" : "015", + "id" : "015", "data" : [ [ "Perl", @@ -493,7 +498,7 @@ 15 ] ], - "id" : "015" + "name" : "015" }, { "name" : "014", @@ -514,8 +519,6 @@ "id" : "014" }, { - "name" : "013", - "id" : "013", "data" : [ [ "Perl", @@ -529,7 +532,9 @@ "Blog", 13 ] - ] + ], + "id" : "013", + "name" : "013" }, { "data" : [ @@ -550, |
