diff options
26 files changed, 1122 insertions, 766 deletions
diff --git a/challenge-045/alicia-bielsa/perl/ch-1.pl b/challenge-045/alicia-bielsa/perl/ch-1.pl new file mode 100644 index 0000000000..a2bfe07b85 --- /dev/null +++ b/challenge-045/alicia-bielsa/perl/ch-1.pl @@ -0,0 +1,75 @@ +#Square Secret Code +#The squate secret code mechanism first removes any space from the original message. +#Then it lays down the message in a row of 8 columns. +#The coded message is then obtained by reading down the columns going left to right. +# +#For example, the message is “The quick brown fox jumps over the lazy dog”. +# +#Then the message would be laid out as below: +# +#thequick +#brownfox +#jumpsove +#rthelazy +#dog +#The code message would be as below: +# +#tbjrd hruto eomhg qwpe unsl ifoa covz kxey +#Write a script that accepts a message from command line and prints the equivalent coded message. + + +use strict; +use warnings; +use Data::Dumper; + + +my $askForInput = 1; +my $errorMessage = ''; +my $columnLength = 8; + +while ($askForInput){ + + if ($errorMessage ){ + print "ERROR: $errorMessage\n"; + } + my $input = getInput(); + print "Input: '$input'\n"; + if ($input =~ /^q|quit$/i){ + print "Bye bye\n"; + $askForInput = 0; + } elsif ($input =~ /\S+/){ + $errorMessage = ''; + my $messageEncoded = encodeMessage($input); + print "\n>>>>>>>>>>>>>>>>Encoded message: $messageEncoded\n"; + } else { + $errorMessage = "ERROR, no valid message was entered\n"; + } + +} + +sub getInput { + print "------------------------------\n"; + print "Enter your message to be coded\nEnter quit(q) to exit\n"; + print "------------------------------\n"; + my $input = <STDIN>; + chomp($input); + return $input; +} + +sub encodeMessage { + my $message = shift; + my @aSubMessages = (); + my $messageEncoded = ''; + $message =~ s%\s+%%g; + my @aEncodedGroups = (); + my @aMessage = split ('', $message); + foreach my $indexMessage (0..$#aMessage){ + my $indexSubgroup = $indexMessage % $columnLength ; + unless (defined $aEncodedGroups[$indexSubgroup]){ + $aEncodedGroups[$indexSubgroup] = ''; + } + $aEncodedGroups[$indexSubgroup] .= $aMessage[$indexMessage]; #t + } + $messageEncoded = join(' ', @aEncodedGroups); + return $messageEncoded ; +} diff --git a/challenge-045/alicia-bielsa/perl/ch-2.pl b/challenge-045/alicia-bielsa/perl/ch-2.pl new file mode 100644 index 0000000000..cc4312fe2c --- /dev/null +++ b/challenge-045/alicia-bielsa/perl/ch-2.pl @@ -0,0 +1,12 @@ +#Write a script that dumps its own source code. +#For example, say, the script name is ch-2.pl then the following command should returns nothing. +#perl ch-2.pl | diff - ch-2.pl + +use strict; +use warnings; + +open (my $fh_file , '<', $0 ) or die "Error reading file"; +while (my $line = <$fh_file>){ + print $line; +} +close ($fh_file);
\ No newline at end of file diff --git a/challenge-045/athanasius/perl/ch-1.pl b/challenge-045/athanasius/perl/ch-1.pl new file mode 100644 index 0000000000..da06db6d17 --- /dev/null +++ b/challenge-045/athanasius/perl/ch-1.pl @@ -0,0 +1,108 @@ +#!perl + +################################################################################ +=comment + +Perl Weekly Challenge 045 +========================= + +Task #1 +------- +*Square Secret Code* +The square secret code mechanism first removes any space from the original +message. Then it lays down the message in a row of 8 columns. The coded message +is then obtained by reading down the columns going left to right. + +For example, the message is *"The quick brown fox jumps over the lazy dog".* + +Then the message would be laid out as below: + + thequick + brownfox + jumpsove + rthelazy + dog + +The code message would be as below: + + tbjrd hruto eomhg qwpe unsl ifoa covz kxey + +Write a script that accepts a message from command line and prints the equiva- +lent coded message. + +=cut +################################################################################ + +#--------------------------------------# +# Copyright © 2020 PerlMonk Athanasius # +#--------------------------------------# + +use strict; +use warnings; +use Const::Fast; + +const my $COLUMNS => 8; + +BEGIN +{ + $| = 1; + print "\n"; +} + +#=============================================================================== +MAIN: +#=============================================================================== +{ + @ARGV > 0 or die "Missing command-line message\n"; + + my $plain = join '', @ARGV; + my $encoded = encode($plain); + my $decoded = decode($encoded); + + print "Original message:\n>$plain<\n"; + print "\nEncoded message:\n>$encoded<\n"; + print "\nDecoded message:\n>$decoded<\n"; + + $decoded eq $plain or die "\nCoding error\n"; +} + +#------------------------------------------------------------------------------- +sub encode +#------------------------------------------------------------------------------- +{ + my ($plain) = @_; + my @rows; + push @rows, substr($plain, 0, $COLUMNS, '') while $plain; + my $encoded = ''; + + for my $col (0 .. $COLUMNS - 1) + { + $encoded .= ' ' if $encoded; + + for my $row (0 .. $#rows) + { + my $text = $rows[$row]; + $encoded .= substr($text, $col, 1) if $col < length $text; + } + } + + return $encoded; +} + +#------------------------------------------------------------------------------- +sub decode +#------------------------------------------------------------------------------- +{ + my ($encoded) = @_; + my @rows = split /\s+/, $encoded; + my $decoded = ''; + + for my $col (0 .. length($rows[0]) - 1) + { + $decoded .= substr($rows[$_], $col, 1) for 0 .. $#rows; + } + + return $decoded; +} + +################################################################################ diff --git a/challenge-045/e-choroba/blog.txt b/challenge-045/e-choroba/blog.txt new file mode 100644 index 0000000000..42c7eaae3f --- /dev/null +++ b/challenge-045/e-choroba/blog.txt @@ -0,0 +1 @@ +http://blogs.perl.org/users/e_choroba/2020/01/perl-weekly-challenge-045-square-secret-code-source-dumper.html diff --git a/challenge-045/e-choroba/perl/ch-2a.pl b/challenge-045/e-choroba/perl/ch-2a.pl index a98ab5bf84..93f8ad483c 100755 --- a/challenge-045/e-choroba/perl/ch-2a.pl +++ b/challenge-045/e-choroba/perl/ch-2a.pl @@ -3,6 +3,6 @@ use warnings; use strict; seek *DATA, 0 , 0; -print while <DATA>; +print <DATA>; __DATA__ diff --git a/challenge-045/ryan-thompson/README b/challenge-045/ryan-thompson/README deleted file mode 100644 index 53b1e7cfa0..0000000000 --- a/challenge-045/ryan-thompson/README +++ /dev/null @@ -1 +0,0 @@ -Solutions by Ryan Thompson. diff --git a/challenge-045/ryan-thompson/README.md b/challenge-045/ryan-thompson/README.md new file mode 100644 index 0000000000..e9331e27a2 --- /dev/null +++ b/challenge-045/ryan-thompson/README.md @@ -0,0 +1,23 @@ +# Ryan Thompson + +## Solution links: + +### Square Secret Code + + * [Perl](perl/ch-1.pl) + * [Raku](raku/ch-1.p6) + +### Quine + + * [Perl Cheaty](perl/ch-2.pl) + * [Perl Trivial](perl/ch-2a.pl) + * [Perl Colorful](perl/ch-2b.pl) + * [Raku Cheaty](raku/ch-2.p6) + * [Raku Quine](raku/ch-2a.p6) + +## Blogs + +Two blog posts this week: + + * [Square Secret Code](http://www.ry.ca/2020/01/square-secret-code/) + * [Quine](http://www.ry.ca/2020/02/quine/) diff --git a/challenge-045/ryan-thompson/blog.txt b/challenge-045/ryan-thompson/blog.txt new file mode 100644 index 0000000000..42be1e7b97 --- /dev/null +++ b/challenge-045/ryan-thompson/blog.txt @@ -0,0 +1 @@ +http://www.ry.ca/2020/01/square-secret-code/ diff --git a/challenge-045/ryan-thompson/blog1.txt b/challenge-045/ryan-thompson/blog1.txt new file mode 100644 index 0000000000..3aae9ee690 --- /dev/null +++ b/challenge-045/ryan-thompson/blog1.txt @@ -0,0 +1 @@ +http://www.ry.ca/2020/02/quine/ diff --git a/challenge-045/ryan-thompson/perl/ch-1.pl b/challenge-045/ryan-thompson/perl/ch-1.pl new file mode 100644 index 0000000000..695f96340b --- /dev/null +++ b/challenge-045/ryan-thompson/perl/ch-1.pl @@ -0,0 +1,25 @@ +#!/usr/bin/env perl +# +# ch-1.pl - Square secret code +# +# Ryan Thompson <rjt@cpan.org> + +use 5.010; +use warnings; +use strict; + +use constant COLUMNS => 8; + +my $plaintext = 'The quick brown fox jumps over the lazy dog'; + +say encode($ARGV[0] // $plaintext); + +sub encode { + local $_ = lc shift; + s/\s//g; + my ($i, @s); + + map { $s[$i++ % COLUMNS] .= $_ } split ''; + + join ' ', @s; +} diff --git a/challenge-045/ryan-thompson/perl/ch-2.pl b/challenge-045/ryan-thompson/perl/ch-2.pl new file mode 100644 index 0000000000..9d7534c8e5 --- /dev/null +++ b/challenge-045/ryan-thompson/perl/ch-2.pl @@ -0,0 +1,8 @@ +#!/usr/bin/env perl +# +# ch-2.pl - Cheaty quine, but passes the challenge test +# +# Ryan Thompson <rjt@cpan.org> + +open my $fh, '<', __FILE__; # Or $0 +print do { undef $/; <$fh> }; diff --git a/challenge-045/ryan-thompson/perl/ch-2a.pl b/challenge-045/ryan-thompson/perl/ch-2a.pl new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/challenge-045/ryan-thompson/perl/ch-2a.pl diff --git a/challenge-045/ryan-thompson/perl/ch-2b.pl b/challenge-045/ryan-thompson/perl/ch-2b.pl new file mode 100644 index 0000000000..58bdb7df1d --- /dev/null +++ b/challenge-045/ryan-thompson/perl/ch-2b.pl @@ -0,0 +1,20 @@ +$_=q<" +[0m +[9C[31m,#######.[37m[8C[31m,#######. +[37m[6C[31m,#####[1m####[0;31m####.[37m [31m,#####[1m###[0;31m#####. +[37m[5C[31m,##########[1m##[0;31m###.,###[1m########[0;31m####. +[37m [31m,####################[1m###[0;31m###[1m#####[0;31m###. +[37m [31m#####[1;33m##[37m##[0;31m###[1;33m###[37m##[0;31m##[1;33m##[37m##[0;31m###[1;37m##[31m####[0;31m#### +[37m [31m####:[1;33m##[0;31m:[1;37m##[0;31m#:[1;33m##[0;31m::##:[1;33m##[0;31m:[1;37m##[0;31m#:[1;33m#[37m#[0;31m#[1m####[0;31m### +[37m [31m####:[1;33m####[0;31m##:[1;33m##[37m#[0;31m###:[1;33m####[0;31m##:[1;33m##[0;31m#[1m####[0;31m### +[37m [31m`###:[1;33m##[0;31m:###:[1;33m##[0;31m####:[1;33m##[0;31m:[1;33m#[37m#[0;31m#:[1;33m##[31m####[0;31m###' +[37m[5C[31m`##:[1;33m##[0;31m####:[1;33m###[37m##[0;31m#:[1;33m##[0;31m:[1;33m##[0;31m#:[1;33m###[37m##[0;31m###' +[37m[7C[31m`::#####:::::##::#::##::::::##' +[37m[8C[31m`####################[1m###[0;31m####' +[37m[10C[31m##################[1m##[0;31m####' +[37m[11C[31m`##############[1m##[0;31m####' +[37m[7C[31m [37m [31m [1;33m [0;31m`##############' +[37m[8C[31m [37m [31m [1;33m [0;31m `########' +[37m[10C[31m[7C[1;33m [0;31m `##' [1;33m [30m=[0;34m[[1mr[0;36mj[1mt[37m2[36m0[0;36m2[1;34m0[0;34m][1;30m= +[0m[13C[1;31m[8C[0;31m`'[0m +";print"\$_=q<$_>;eval\n">;eval diff --git a/challenge-045/ryan-thompson/raku/ch-1.p6 b/challenge-045/ryan-thompson/raku/ch-1.p6 new file mode 100644 index 0000000000..ca65f7caa8 --- /dev/null +++ b/challenge-045/ryan-thompson/raku/ch-1.p6 @@ -0,0 +1,18 @@ +#!/usr/bin/env perl6 + +# ch-1.p6 - Square code +# +# Ryan Thompson <rjt@cpan.org> + +sub MAIN( Str $plaintext = 'The quick brown fox jumps over the lazy dog' ) { + say encode($plaintext, 8); +} + +#| Encode plaintext according to the Square Secret Code definition +# $width is by default chosen to give a "square" result +sub encode( Str $plain, Int $width = $plain.chars.sqrt.Int ) { + my @s; + $plain.lc.subst(/\s/,'',:g).comb.kv.map: { @s[$^i % $width] ~= $^str }; + + @s.join(' ') +} diff --git a/challenge-045/ryan-thompson/raku/ch-2.p6 b/challenge-045/ryan-thompson/raku/ch-2.p6 new file mode 100644 index 0000000000..f796b94ee4 --- /dev/null +++ b/challenge-045/ryan-thompson/raku/ch-2.p6 @@ -0,0 +1,7 @@ +#!/usr/bin/env perl6 + +# ch-2.p6 - Not a quine +# +# Ryan Thompson <rjt@cpan.org> + +$*PROGRAM.lines».say diff --git a/challenge-045/ryan-thompson/raku/ch-2a.p6 b/challenge-045/ryan-thompson/raku/ch-2a.p6 new file mode 100644 index 0000000000..4b74792751 --- /dev/null +++ b/challenge-045/ryan-thompson/raku/ch-2a.p6 @@ -0,0 +1 @@ +{.printf($_)}(<{.printf($_)}(<%s>)>)
\ No newline at end of file diff --git a/stats/pwc-current.json b/stats/pwc-current.json index 5580682bc4..406120b5c4 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,41 +1,49 @@ { - "chart" : { - "type" : "column" - }, - "plotOptions" : { - "series" : { - "dataLabels" : { - "enabled" : 1, - "format" : "{point.y}" - }, - "borderWidth" : 0 - } + "title" : { + "text" : "Perl Weekly Challenge - 045" }, "legend" : { "enabled" : 0 }, + "subtitle" : { + "text" : "[Champions: 19] Last updated at 2020-02-01 18:50:07 GMT" + }, + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } + }, "xAxis" : { "type" : "category" }, - "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/>" + "chart" : { + "type" : "column" }, "drilldown" : { "series" : [ { - "id" : "Andrezgz", + "name" : "Alicia Bielsa", + "id" : "Alicia Bielsa", + "data" : [ + [ + "Perl", + 2 + ] + ] + }, + { "data" : [ [ "Perl", 2 ] ], + "id" : "Andrezgz", "name" : "Andrezgz" }, { "id" : "Arne Sommer", + "name" : "Arne Sommer", "data" : [ [ "Perl", @@ -49,22 +57,31 @@ "Blog", 1 ] - ], - "name" : "Arne Sommer" + ] }, { "data" : [ [ "Perl", - 2 + 1 ] ], + "id" : "Athanasius", + "name" : "Athanasius" + }, + { + "name" : "Dave Cross", "id" : "Dave Cross", - "name" : "Dave Cross" + "data" : [ + [ + "Perl", + 2 + ] + ] }, { - "name" : "Dave Jacoby", "id" : "Dave Jacoby", + "name" : "Dave Jacoby", "data" : [ [ "Perl", @@ -77,27 +94,30 @@ ] }, { + "name" : "Duane Powell", "id" : "Duane Powell", "data" : [ [ "Perl", 2 ] - ], - "name" : "Duane Powell" + ] }, { "name" : "E. Choroba", + "id" : "E. Choroba", "data" : [ [ "Perl", 2 + ], + [ + "Blog", + 1 ] - ], - "id" : "E. Choroba" + ] }, { - "name" : "Javier Luque", "data" : [ [ "Perl", @@ -112,10 +132,10 @@ 1 ] ], + "name" : "Javier Luque", "id" : "Javier Luque" }, { - "name" : "Luca Ferrari", "data" : [ [ "Raku", @@ -126,50 +146,50 @@ 1 ] ], + "name" : "Luca Ferrari", "id" : "Luca Ferrari" }, { + "id" : "Markus Holzer", + "name" : "Markus Holzer", "data" : [ [ "Raku", 2 ] - ], - "id" : "Markus Holzer", - "name" : "Markus Holzer" + ] }, { + "id" : "Nazareno Delucca", + "name" : "Nazareno Delucca", "data" : [ [ "Perl", 2 ] - ], - "id" : "Nazareno Delucca", - "name" : "Nazareno Delucca" + ] }, { + "id" : "Peter Scott", "name" : "Peter Scott", "data" : [ [ "Perl", 1 ] - ], - "id" : "Peter Scott" + ] }, { + "name" : "Rage311", "id" : "Rage311", "data" : [ [ "Perl", 2 ] - ], - "name" : "Rage311" + ] }, { - "id" : "Roger Bell West", "data" : [ [ "Perl", @@ -180,9 +200,11 @@ 2 ] ], + "id" : "Roger Bell West", "name" : "Roger Bell West" }, { + "name" : "Ruben Westerberg", "id" : "Ruben Westerberg", "data" : [ [ @@ -193,80 +215,95 @@ "Raku", 2 ] - ], - "name" : "Ruben Westerberg" + ] }, { + "name" : "Ryan Thompson", + "id" : "Ryan Thompson", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ], + [ + "Blog", + 2 + ] + ] + }, + { + "id" : "Simon Proctor", "name" : "Simon Proctor", "data" : [ [ "Raku", 2 ] - ], - "id" : "Simon Proctor" + ] }, { - "name" : "Wanderdoc", "data" : [ [ "Perl", 2 ] ], - "id" : "Wanderdoc" + "id" : "Wanderdoc", + "name" : "Wanderdoc" } ] }, - "yAxis" : { - "title" : { - "text" : "Total Solutions" - } - }, - "title" : { - "text" : "Perl Weekly Challenge - 045" - }, - "subtitle" : { - "text" : "[Champions: 16] Last updated at 2020-01-31 18:10:43 GMT" - }, "series" : [ { - "colorByPoint" : 1, "data" : [ { - "drilldown" : "Andrezgz", - "name" : "Andrezgz", + "name" : "Alicia Bielsa", + "drilldown" : "Alicia Bielsa", "y" : 2 }, { - "y" : 5, + "y" : 2, + "drilldown" : "Andrezgz", + "name" : "Andrezgz" + }, + { "name" : "Arne Sommer", - "drilldown" : "Arne Sommer" + "drilldown" : "Arne Sommer", + "y" : 5 + }, + { + "name" : "Athanasius", + "drilldown" : "Athanasius", + "y" : 1 }, { "name" : "Dave Cross", - "y" : 2, - "drilldown" : "Dave Cross" + "drilldown" : "Dave Cross", + "y" : 2 }, { - "drilldown" : "Dave Jacoby", + "y" : 3, "name" : "Dave Jacoby", - "y" : 3 + "drilldown" : "Dave Jacoby" }, { "y" : 2, - "name" : "Duane Powell", - "drilldown" : "Duane Powell" + "drilldown" : "Duane Powell", + "name" : "Duane Powell" }, { - "name" : "E. Choroba", - "y" : 2, - "drilldown" : "E. Choroba" + "y" : 3, + "drilldown" : "E. Choroba", + "name" : "E. Choroba" }, { - "y" : 5, "name" : "Javier Luque", - "drilldown" : "Javier Luque" + "drilldown" : "Javier Luque", + "y" : 5 }, { "drilldown" : "Luca Ferrari", @@ -274,19 +311,19 @@ "y" : 3 }, { - "name" : "Markus Holzer", "y" : 2, - "drilldown" : "Markus Holzer" + "drilldown" : "Markus Holzer", + "name" : "Markus Holzer" }, { - "drilldown" : "Nazareno Delucca", + "y" : 2, "name" : "Nazareno Delucca", - "y" : 2 + "drilldown" : "Nazareno Delucca" }, { - "name" : "Peter Scott", "y" : 1, - "drilldown" : "Peter Scott" + "drilldown" : "Peter Scott", + "name" : "Peter Scott" }, { "y" : 2, @@ -294,27 +331,47 @@ "drilldown" : "Rage311" }, { - "name" : "Roger Bell West", "y" : 4, - "drilldown" : "Roger Bell West" + "drilldown" : "Roger Bell West", + "name" : "Roger Bell West" }, { - "drilldown" : "Ruben Westerberg", "y" : 4, - "name" : "Ruben Westerberg" + "name" : "Ruben Westerberg", + "drilldown" : "Ruben Westerberg" + }, + { + "name" : "Ryan Thompson", + "drilldown" : "Ryan Thompson", + "y" : 6 }, { "y" : 2, - "name" : "Simon Proctor", - "drilldown" : "Simon Proctor" + "drilldown" : "Simon Proctor", + "name" : "Simon Proctor" }, { - "drilldown" : "Wanderdoc", + "y" : 2, "name" : "Wanderdoc", - "y" : 2 + "drilldown" : "Wanderdoc" } ], + "colorByPoint" : 1, "name" : "Perl Weekly Challenge - 045" } - ] + ], + "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/>" + }, + "plotOptions" : { + "series" : { + "borderWidth" : 0, + "dataLabels" : { + "format" : "{point.y}", + "enabled" : 1 + } + } + } } diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index f11d5f9f3e..005eb7c44d 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -1,63 +1,63 @@ { - "title" : { - "text" : "Perl Weekly Challenge Contributions [2019 - 2020]" - }, - "subtitle" : { - "text" : "Last updated at 2020-01-31 18:10:43 GMT" + "tooltip" : { + "pointFormat" : "<b>{point.y:.0f}</b>" }, "series" : [ { "data" : [ [ "Blog", - 477 + 480 ], [ "Perl", - 1832 + 1837 ], [ "Raku", - 1112 + 1114 ] ], "dataLabels" : { - "enabled" : "true", - "y" : 10, - "format" : "{point.y:.0f}", - "align" : "right", + "rotation" : -90, "style" : { "fontSize" : "13px", "fontFamily" : "Verdana, sans-serif" }, + "y" : 10, + "align" : "right", + "enabled" : "true", "color" : "#FFFFFF", - "rotation" : -90 + "format" : "{point.y:.0f}" }, "name" : "Contributions" } ], + "chart" : { + "type" : "column" + }, + "xAxis" : { + "type" : "category", + "labels" : { + "style" : { + "fontSize" : "13px", + "fontFamily" : "Verdana, sans-serif" + } + } + }, + "subtitle" : { + "text" : "Last updated at 2020-02-01 18:50:07 GMT" + }, "yAxis" : { + "min" : 0, "title" : { "text" : null - }, - "min" : 0 + } }, "legend" : { |
