diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2020-07-20 14:37:38 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2020-07-20 14:37:38 +0100 |
| commit | 58ac447afca0a3469b65da82b48e200058a9ce1a (patch) | |
| tree | bc169b357c8ffa11063e5c97ba50862f365cbaaa | |
| parent | 3e7a89a2cf23875c4e369aba8f23af0092cc0c09 (diff) | |
| download | perlweeklychallenge-club-58ac447afca0a3469b65da82b48e200058a9ce1a.tar.gz perlweeklychallenge-club-58ac447afca0a3469b65da82b48e200058a9ce1a.tar.bz2 perlweeklychallenge-club-58ac447afca0a3469b65da82b48e200058a9ce1a.zip | |
- Added Raku solutions to the Challenge #070.
| -rwxr-xr-x | challenge-070/mohammad-anwar/perl/ch-2a.pl | 4 | ||||
| -rwxr-xr-x | challenge-070/mohammad-anwar/raku/ch-1.raku | 49 | ||||
| -rwxr-xr-x | challenge-070/mohammad-anwar/raku/ch-1a.raku | 33 | ||||
| -rwxr-xr-x | challenge-070/mohammad-anwar/raku/ch-2.raku | 44 | ||||
| -rwxr-xr-x | challenge-070/mohammad-anwar/raku/ch-2a.raku | 48 | ||||
| -rw-r--r-- | stats/pwc-current.json | 80 | ||||
| -rw-r--r-- | stats/pwc-language-breakdown-summary.json | 58 | ||||
| -rw-r--r-- | stats/pwc-language-breakdown.json | 464 | ||||
| -rw-r--r-- | stats/pwc-leaders.json | 352 | ||||
| -rw-r--r-- | stats/pwc-summary-1-30.json | 56 | ||||
| -rw-r--r-- | stats/pwc-summary-121-150.json | 44 | ||||
| -rw-r--r-- | stats/pwc-summary-151-180.json | 98 | ||||
| -rw-r--r-- | stats/pwc-summary-31-60.json | 46 | ||||
| -rw-r--r-- | stats/pwc-summary-61-90.json | 38 | ||||
| -rw-r--r-- | stats/pwc-summary-91-120.json | 108 | ||||
| -rw-r--r-- | stats/pwc-summary.json | 388 |
16 files changed, 1044 insertions, 866 deletions
diff --git a/challenge-070/mohammad-anwar/perl/ch-2a.pl b/challenge-070/mohammad-anwar/perl/ch-2a.pl index dcbb7654f8..9ec6456ef2 100755 --- a/challenge-070/mohammad-anwar/perl/ch-2a.pl +++ b/challenge-070/mohammad-anwar/perl/ch-2a.pl @@ -16,10 +16,10 @@ use Test::Deep; is_deeply( [ generate_gray_code_sequence(3) ], [ 0, 1, 3, 2, 6, 7, 5, 4 ], - 'testing 3-bit gray code sequence' ); + 'testing 3-bit gray code sequence.' ); is_deeply( [ generate_gray_code_sequence(4) ], [ 0, 1, 3, 2, 6, 7, 5, 4, 12, 13, 15, 14, 10, 11, 9, 8 ], - 'testing 4-bit gray code sequence' ); + 'testing 4-bit gray code sequence.' ); done_testing; diff --git a/challenge-070/mohammad-anwar/raku/ch-1.raku b/challenge-070/mohammad-anwar/raku/ch-1.raku new file mode 100755 index 0000000000..4dc8463077 --- /dev/null +++ b/challenge-070/mohammad-anwar/raku/ch-1.raku @@ -0,0 +1,49 @@ +#!/usr/bin/env raku + +# +# Perl Weekly Challenge - 070 +# +# Task #1: Character Swapping +# +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-070 +# + +use v6.d; + +sub MAIN(Str :$S = 'perlandraku', Int :$C = 3, Int :$O = 4) { + ($S, swap($S, $C, $O)).join(' => ').say; +} + +sub swap(Str $string, Int $count, Int $offset) { + + my $length = $string.chars; + my @array = $string.comb; + for 1..$count -> $i { + my $a = $i % $length; + my $b = ($i + $offset) % $length; + (@array[$a], @array[$b]) = (@array[$b], @array[$a]); + } + + return @array.join(''); +} + +=finish +my $S = $ARGV[0] || 'perlandraku'; +my $C = $ARGV[1] || 3; +my $O = $ARGV[2] || 4; + +print sprintf("%s => %s\n", $S, swap($S, $C, $O)); + +sub swap { + my ($string, $count, $offset) = @_; + + my $length = length($string); + my @array = split //, $string; + foreach my $i (1..$count) { + my $a = $i % $length; + my $b = ($i + $offset) % $length; + ($array[$a], $array[$b]) = ($array[$b], $array[$a]); + } + + return join '', @array; +} diff --git a/challenge-070/mohammad-anwar/raku/ch-1a.raku b/challenge-070/mohammad-anwar/raku/ch-1a.raku new file mode 100755 index 0000000000..5a50b0f603 --- /dev/null +++ b/challenge-070/mohammad-anwar/raku/ch-1a.raku @@ -0,0 +1,33 @@ +#!/usr/bin/env raku + +# +# Perl Weekly Challenge - 070 +# +# Task #1: Character Swapping +# +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-070 +# + +use Test; + +is swap('perlandraku', 3, 4), + 'pndraerlaku', + 'testing perlandraku.'; +is swap('weeklychallenge', 5, 2), + 'wklycheeallenge', + 'testing weeklychallenge.'; + +done-testing; + +sub swap(Str $string, Int $count, Int $offset) { + + my $length = $string.chars; + my @array = $string.comb; + for 1..$count -> $i { + my $a = $i % $length; + my $b = ($i + $offset) % $length; + (@array[$a], @array[$b]) = (@array[$b], @array[$a]); + } + + return @array.join(''); +} diff --git a/challenge-070/mohammad-anwar/raku/ch-2.raku b/challenge-070/mohammad-anwar/raku/ch-2.raku new file mode 100755 index 0000000000..33da502653 --- /dev/null +++ b/challenge-070/mohammad-anwar/raku/ch-2.raku @@ -0,0 +1,44 @@ +#!/usr/bin/env raku + +# +# Perl Weekly Challenge - 070 +# +# Task #2: Gray Code Sequence +# +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-070 +# + +use v6.d; + +sub MAIN(Int :$N = 3) { + say sprintf("%d-bit Gray Code Sequence:\n[%s]", + $N, generate-gray-code-sequence($N).join(', ')); +} + +sub generate-gray-code-sequence(Int $n) { + + my %S = ( + 2 => ['00', '01', '11', '10'], + ); + + for 3 .. $n -> $i { + my $S1 = %S{$i - 1}; + my $S2 = [ |$S1.reverse ]; + $S1.map({ $_ = '0' ~ $_ }); + $S2.map({ $_ = '1' ~ $_ }); + %S{$i} = [ |$S1, |$S2 ]; + } + + my @gray_codes = (); + for %S{$n} -> $list { + for |$list -> $binary { + @gray_codes.push: to-decimal($binary); + } + } + + return |@gray_codes; +} + +sub to-decimal(Str $binary) { + return ":2<$binary>".Int; +} diff --git a/challenge-070/mohammad-anwar/raku/ch-2a.raku b/challenge-070/mohammad-anwar/raku/ch-2a.raku new file mode 100755 index 0000000000..67c94c5d6c --- /dev/null +++ b/challenge-070/mohammad-anwar/raku/ch-2a.raku @@ -0,0 +1,48 @@ +#!/usr/bin/env raku + +# +# Perl Weekly Challenge - 070 +# +# Task #2: Gray Code Sequence +# +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-070 +# + +use Test; + +is-deeply generate-gray-code-sequence(3), + (0, 1, 3, 2, 6, 7, 5, 4), + 'testing 3-bin grey code sequence.'; +is-deeply generate-gray-code-sequence(4), + (0, 1, 3, 2, 6, 7, 5, 4, 12, 13, 15, 14, 10, 11, 9, 8), + 'testing 4-bit grey code sequence.'; + +done-testing; + +sub generate-gray-code-sequence(Int $n) { + + my %S = ( + 2 => ['00', '01', '11', '10'], + ); + + for 3 .. $n -> $i { + my $S1 = %S{$i - 1}; + my $S2 = [ |$S1.reverse ]; + $S1.map({ $_ = '0' ~ $_ }); + $S2.map({ $_ = '1' ~ $_ }); + %S{$i} = [ |$S1, |$S2 ]; + } + + my @gray_codes = (); + for %S{$n} -> $list { + for |$list -> $binary { + @gray_codes.push: to-decimal($binary); + } + } + + return |@gray_codes; +} + +sub to-decimal(Str $binary) { + return ":2<$binary>".Int; +} diff --git a/stats/pwc-current.json b/stats/pwc-current.json index 4528d8f1cb..215245d3e6 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,26 +1,43 @@ { + "subtitle" : { + "text" : "[Champions: 5] Last updated at 2020-07-20 13:37:19 GMT" + }, + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } + }, + "tooltip" : { + "followPointer" : 1, + "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/>" + }, + "legend" : { + "enabled" : 0 + }, "series" : [ { + "name" : "Perl Weekly Challenge - 070", "data" : [ { "y" : 4, - "drilldown" : "Andrew Shitov", - "name" : "Andrew Shitov" + "name" : "Andrew Shitov", + "drilldown" : "Andrew Shitov" }, { "y" : 5, - "name" : "Javier Luque", - "drilldown" : "Javier Luque" + "drilldown" : "Javier Luque", + "name" : "Javier Luque" }, { + "y" : 4, "name" : "Mohammad S Anwar", - "drilldown" : "Mohammad S Anwar", - "y" : 2 + "drilldown" : "Mohammad S Anwar" }, { - "y" : 4, + "drilldown" : "Roger Bell_West", "name" : "Roger Bell_West", - "drilldown" : "Roger Bell_West" + "y" : 4 }, { "y" : 3, @@ -28,10 +45,18 @@ "name" : "Simon Green" } ], - "colorByPoint" : 1, - "name" : "Perl Weekly Challenge - 070" + "colorByPoint" : 1 } ], + "plotOptions" : { + "series" : { + "borderWidth" : 0, + "dataLabels" : { + "enabled" : 1, + "format" : "{point.y}" + } + } + }, "drilldown" : { "series" : [ { @@ -49,7 +74,6 @@ "id" : "Andrew Shitov" }, { - "name" : "Javier Luque", "data" : [ [ "Perl", @@ -64,15 +88,20 @@ 1 ] ], + "name" : "Javier Luque", "id" : "Javier Luque" }, { - "name" : "Mohammad S Anwar", "id" : "Mohammad S Anwar", + "name" : "Mohammad S Anwar", "data" : [ [ "Perl", 2 + ], + [ + "Raku", + 2 ] ] }, @@ -91,6 +120,7 @@ "name" : "Roger Bell_West" }, { + "id" : "Simon Green", "data" : [ [ "Perl", @@ -101,39 +131,13 @@ 1 ] ], - "id" : "Simon Green", "name" : "Simon Green" } ] }, - "subtitle" : { - "text" : "[Champions: 5] Last updated at 2020-07-20 10:56:00 GMT" - }, "xAxis" : { "type" : "category" }, - "plotOptions" : { - "series" : { - "borderWidth" : 0, - "dataLabels" : { - "enabled" : 1, - "format" : "{point.y}" - } - } - }, - "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 - }, - "legend" : { - "enabled" : 0 - }, - "yAxis" : { - "title" : { - "text" : "Total Solutions" - } - }, "title" : { "text" : "Perl Weekly Challenge - 070" }, diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index cda03e06f1..21e6219f9b 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -1,22 +1,4 @@ { - "chart" : { - "type" : "column" - }, - "title" : { - "text" : "Perl Weekly Challenge Contributions [2019 - 2020]" - }, - "yAxis" : { - "min" : 0, - "title" : { - "text" : null - } - }, - "legend" : { - "enabled" : "false" - }, - "tooltip" : { - "pointFormat" : "<b>{point.y:.0f}</b>" - }, "xAxis" : { "labels" : { "style" : { @@ -26,11 +8,18 @@ }, "type" : "category" }, - "subtitle" : { - "text" : "Last updated at 2020-07-20 10:56:00 GMT" + "title" : { + "text" : "Perl Weekly Challenge Contributions [2019 - 2020]" + }, + "chart" : { + "type" : "column" + }, + "legend" : { + "enabled" : "false" }, "series" : [ { + "name" : "Contributions", "data" : [ [ "Blog", @@ -42,22 +31,33 @@ ], [ "Raku", - 1838 + 1840 ] ], "dataLabels" : { - "format" : "{point.y:.0f}", - "align" : "right", - "y" : 10, "style" : { "fontFamily" : "Verdana, sans-serif", "fontSize" : "13px" }, + "y" : 10, + "enabled" : "true", "color" : "#FFFFFF", - "rotation" : -90, - "enabled" : "true" - }, - "name" : "Contributions" + "align" : "right", + "format" : "{point.y:.0f}", + "rotation" : -90 + } } - ] + ], + "subtitle" : { + "text" : "Last updated at 2020-07-20 13:37:19 GMT" + }, + "yAxis" : { + "title" : { + "text" : null + }, + "min" : 0 + }, + "tooltip" : { + "pointFormat" : "<b>{point.y:.0f}</b>" + } } diff --git a/stats/pwc-language-breakdown.json b/stats/pwc-language-breakdown.json index e316bf405f..4a44c0ce5a 100644 --- a/stats/pwc-language-breakdown.json +++ b/stats/pwc-language-breakdown.json @@ -1,4 +1,13 @@ { + "xAxis" : { + "type" : "category" + }, + "title" : { + "text" : "Perl Weekly Challenge Language" + }, + "chart" : { + "type" : "column" + }, "plotOptions" : { "series" : { "dataLabels" : { @@ -8,15 +17,10 @@ "borderWidth" : 0 } }, - "xAxis" : { - "type" : "category" - }, - "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2020-07-20 10:56:00 GMT" - }, "drilldown" : { "series" : [ { + "id" : "001", "name" : "001", "data" : [ [ @@ -31,11 +35,9 @@ "Blog", 11 ] - ], - "id" : "001" + ] }, { - "id" : "002", "data" : [ [ "Perl", @@ -50,11 +52,10 @@ 10 ] ], - "name" : "002" + "name" : "002", + "id" : "002" }, { - "name" : "003", - "id" : "003", "data" : [ [ "Perl", @@ -68,11 +69,12 @@ "Blog", 9 ] - ] + ], + "name" : "003", + "id" : "003" }, { "name" : "004", - "id" : "004", "data" : [ [ "Perl", @@ -86,10 +88,11 @@ "Blog", 10 ] - ] + ], + "id" : "004" }, { - "id" : "005", + "name" : "005", "data" : [ [ "Perl", @@ -104,9 +107,10 @@ 12 ] ], - "name" : "005" + "id" : "005" }, { + "id" : "006", "data" : [ [ "Perl", @@ -121,7 +125,6 @@ 7 ] ], - "id" : "006", "name" : "006" }, { @@ -144,6 +147,7 @@ }, { "id" : "008", + "name" : "008", "data" : [ [ "Perl", @@ -157,10 +161,10 @@ "Blog", 12 ] - ], - "name" : "008" + ] }, { + "id" : "009", "data" : [ [ "Perl", @@ -175,12 +179,11 @@ 13 ] ], - "id" : "009", "name" : "009" }, { - "name" : "010", "id" : "010", + "name" : "010", "data" : [ [ "Perl", @@ -198,7 +201,6 @@ }, { "name" : "011", - "id" : "011", "data" : [ [ "Perl", @@ -212,10 +214,10 @@ "Blog", 10 ] - ] + ], + "id" : "011" }, { - "name" : "012", "data" : [ [ "Perl", @@ -230,9 +232,12 @@ 11 ] ], + "name" : "012", "id" : "012" }, { + "id" : "013", + "name" : "013", "data" : [ [ "Perl", @@ -246,11 +251,11 @@ "Blog", 13 ] - ], - "id" : "013", - "name" : "013" + ] }, { + "id" : "014", + "name" : "014", "data" : [ [ "Perl", @@ -264,12 +269,9 @@ "Blog", 15 ] - ], - "id" : "014", - "name" : "014" + ] }, { - "name" : "015", "data" : [ [ "Perl", @@ -284,10 +286,10 @@ 15 ] ], + "name" : "015", "id" : "015" }, { - "name" : "016", "id" : "016", "data" : [ [ @@ -302,10 +304,11 @@ "Blog", 12 ] - ] + ], + "name" : "016" }, { - "id" : "017", + "name" : "017", "data" : [ [ "Perl", @@ -320,9 +323,10 @@ 12 ] ], - "name" : "017" + "id" : "017" }, { + "id" : "018", "name" : "018", "data" : [ [ @@ -337,11 +341,10 @@ "Blog", 14 ] - ], - "id" : "018" + ] }, { - "name" : "019", + "id" : "019", "data" : [ [ "Perl", @@ -356,9 +359,10 @@ 13 ] ], - "id" : "019" + "name" : "019" }, { + "id" : "020", "data" : [ [ "Perl", @@ -373,10 +377,10 @@ 13 ] ], - "id" : "020", "name" : "020" }, { + "id" : "021", "data" : [ [ "Perl", @@ -391,11 +395,9 @@ 10 ] ], - "id" : "021", "name" : "021" }, { - "name" : "022", "id" : "022", "data" : [ [ @@ -410,10 +412,12 @@ "Blog", 10 ] - ] + ], + "name" : "022" }, { "id" : "023", + "name" : "023", "data" : [ [ "Perl", @@ -427,10 +431,11 @@ "Blog", 12 ] - ], - "name" : "023" + ] }, { + "id" : "024", + "name" : "024", "data" : [ [ "Perl", @@ -444,12 +449,10 @@ "Blog", 11 ] - ], - "id" : "024", - "name" : "024" + ] }, { - "id" : "025", + "name" : "025", "data" : [ [ "Perl", @@ -464,10 +467,10 @@ 12 ] ], - "name" : "025" + "id" : "025" }, { - "id" : "026", + "name" : "026", "data" : [ [ "Perl", @@ -482,9 +485,10 @@ 10 ] ], - "name" : "026" + "id" : "026" }, { + "id" : "027", "name" : "027", "data" : [ [ @@ -499,10 +503,10 @@ "Blog", 9 ] - ], - "id" : "027" + ] }, { + "id" : "028", "data" : [ [ "Perl", @@ -517,11 +521,9 @@ 9 ] ], - "id" : "028", "name" : "028" }, { - "id" : "029", "data" : [ [ "Perl", @@ -536,11 +538,12 @@ 12 ] ], - "name" : "029" + "name" : "029", + "id" : "029" }, { - "name" : "030", "id" : "030", + "name" : "030", "data" : [ [ "Perl", @@ -558,7 +561,6 @@ }, { "name" : "031", - "id" : "031", "data" : [ [ "Perl", @@ -572,10 +574,10 @@ "Blog", 9 ] - ] + ], + "id" : "031" }, { - "name" : "032", "data" : [ [ "Perl", @@ -590,10 +592,10 @@ 10 ] ], + "name" : "032", "id" : "032" }, { - "name" : "033", "data" : [ [ "Perl", @@ -608,11 +610,11 @@ 10 ] ], + "name" : "033", "id" : "033" }, { "name" : "034", - "id" : "034", "data" : [ [ "Perl", @@ -626,11 +628,11 @@ "Blog", 11 ] - ] + ], + "id" : "034" }, { "name" : "035", - "id" : "035", "data" : [ [ "Perl", @@ -644,10 +646,10 @@ "Blog", 9 ] - ] + ], + "id" : "035" }, { - "name" : "036", "id" : "036", "data" : [ [ @@ -662,10 +664,10 @@ "Blog", 11 ] - ] + ], + "name" : "036" }, { - "id" : "037", "data" : [ [ "Perl", @@ -680,10 +682,10 @@ 9 ] ], - "name" : "037" + "name" : "037", + "id" : "037" }, { - "name" : "038", "data" : [ [ "Perl", @@ -698,6 +700,7 @@ 12 ] ], + "name" : "038", "id" : "038" }, { @@ -719,8 +722,8 @@ "name" : "039" }, { - "name" : "040", "id" : "040", + "name" : "040", "data" : [ [ "Perl", @@ -737,6 +740,7 @@ ] }, { + "id" : "041", "data" : [ [ "Perl", @@ -751,11 +755,9 @@ 9 ] ], - "id" : "041", "name" : "041" }, { - "id" : "042", "data" : [ [ "Perl", @@ -770,10 +772,12 @@ 11 ] ], - "name" : "042" + "name" : "042", + "id" : "042" }, { "id" : "043", + "name" : "043", "data" : [ [ "Perl", @@ -787,10 +791,11 @@ "Blog", 11 ] - ], - "name" : "043" + ] }, { + "id" : "044", + "name" : "044", "data" : [ [ "Perl", @@ -804,11 +809,10 @@ "Blog", 11 ] - ], - "id" : "044", - "name" : "044" + ] }, { + "id" : "045", "name" : "045", "data" : [ [ @@ -823,11 +827,9 @@ "Blog", 11 ] - ], - "id" : "045" + ] }, { - "name" : "046", "data" : [ [ "Perl", @@ -842,9 +844,11 @@ 10 ] ], + "name" : "046", "id" : "046" }, { + "name" : "047", "data" : [ [ "Perl", @@ -859,12 +863,9 @@ 10 ] ], - "id" : "047", - "name" : "047" + "id" : "047" }, { - "name" : "048", - "id" : "048", "data" : [ [ "Perl", @@ -878,11 +879,12 @@ "Blog", 12 ] - ] + ], + "name" : "048", + "id" : "048" }, { "name" : "049", - "id" : "049", "data" : [ [ "Perl", @@ -896,9 +898,12 @@ "Blog", 12 ] - ] + ], + "id" : "049" }, { + "id" : "050", + "name" : "050", "data" : [ [ "Perl", @@ -912,11 +917,10 @@ "Blog", 12 ] - ], - "id" : "050", - "name" : "050" + ] }, { + "id" : "051", "data" : [ [ |
